Getting Started

Introduction

Installation

API Client

Overview

Make an API Request

Replay request from History

Import from cURL

Inspect Traffic

Overview

Filtering Traffic

Save Session

View Request/Response Details

HTTP Rules (Modify Traffic)

Overview

Redirect URL (Map Local, Map Remote)

Replace Strings (Switch Hosts, API Endpoints)

Modify Headers

Modify Request Body

Modify Response Body

Modify Query Params

Modify Cookies

Modify DOM/Inject scripts

Modify User Agents

Modify Response Body

Modifying the request payload is the process of changing the data sent to the server when making an HTTP request. You can use Modify Request Body rule to override the API request body with static data or programmatically modify the existing request payload.

Static Request Body Modification

In this mode, you can enter a static request body (JSON) you want to forward to the server.

Untitled

Rule working but doesn't show updated request body in devtools

Request Body Modifications will not show up in the browser network devtools due to technical constraints. So your rule might actually be working but only doesn't show the updated Request body in the browser devtools.

  1. Source Condition: Source condition is where you set criteria for the rules. You can use URLHost, or Path with RegexContainsWildcard, or Equals to match the source request. Learn more about source conditions here.
  2. Static Request Body: Define the static request body which must be passed to the server.
  3. Source Filters: You can define better targeting conditions and restrict rules to apply on specific web pages (or domains), request types, request methods, or request payloads. Learn more about source filters here.

Programmatic Request Body Modification

The existing request body can be modified programmatically using JavaScript.

Untitled

Programmatic Modification Script (JS) is where you write a JavaScript script that can modify the existing request body programmatically.

Arguments of modifyRequestBody

  1. method (string)- The HTTP method of the request. GET | POST | PUT | DELETE etc.
  2. url (string) - The request URL.
  3. body (string)- The original request body stringified:
'{"app":"requestly","feature":"modify-request"}'

  1. bodyAsJson (JSON object)- The original request body parsed into JSON object:
{
    "app":"requestly",
    "feature":"modify-request"
}

Return type of modifyRequestBody

You can return modified body as string or JSON object.

How to modify the body of a POST request.

We use https://echo.hoppscotch.io/ to test this which echoes back the request.

  1. We make the following POST request.
const options = {
  method: 'POST',
  headers: {'content-type': 'application/json'},
  body: '{"app":"requestly"}'
};

fetch('<https://echo.hoppscotch.io/>', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

  1. Create a Modify Request Body rule uses the following JavaScript. You can find the rule here.
function modifyRequestBody(args) {
  const { method, url, body, bodyAsJson } = args;
  // Change request body below depending upon request attributes received in args
  let newBody;
  if (method === "POST") {
    newBody = bodyAsJson;
    newBody["feature"] = "modify request";
  }
  return newBody;
}

  1. You can see the key feature being added to the request body when hoppscotch echoes back the request.

Popular Use Cases:

FAQ