Modify Request Body

Learn to modify HTTP request payloads with static data or JavaScript. A guide to setting up rules for testing APIs, handling GraphQL, and debugging payloads.


The Modify Request Body rule enables you to override or programmatically modify the data sent to the server in an HTTP request body. This rule is particularly useful for debugging, testing, and dynamically altering API payloads.

Why Use the Modify Request Body Rule?

  • Static Request Body Modification: Replace the request body with predefined static data for consistent testing.

  • Programmatic Request Body Modification: Dynamically modify the request payload using JavaScript based on specific conditions.

  • Testing Edge Cases: Simulate unsupported or erroneous fields in request payloads to evaluate server responses.

  • Send Additional Data: Include extra fields in the payload for enhanced server communication, especially for GraphQL queries or APIs.

How to Configure the Rule

1

Open HTTP Rules and Create a New Rule

Navigate to the HTTP Rules tab in the web or desktop app. Click on + New Rule and select Modify Request Body from the options.

2

Name and Describe Your Rule

Provide a descriptive name for the rule to keep your setup organized. Optionally, add a brief description explaining its purpose for easier identification later.

3

Define the Source Condition

Define where the rule should be applied by specifying criteria such as URL, Host, or Path. You can choose from options like Regex, Contains, Wildcard, or Equals, or use a Filter for more precise conditions.

Example:

  • Condition Type: URL

  • Operator: Contains

  • Value: api.example.com

Learn more about source conditions here.

4

Choose Static or Programmatic Modification

You can override a request body using a static JSON or programatically using JS.

Static Request Body

Enter the static JSON payload you want to forward to the server.

{
  "key": "value",
  "feature": "modify-request"
}

You can also use Dynamic Data to override GraphQL APIs by detecting the operation name in the request body.

5

Save and Activate the Rule

Click Save to store the rule and toggle it ON. This will apply the rule to the defined source conditions.

6

Test the Rule

This feature is available on the browser extension only.

To ensure the rule is working correctly, click the Test button and enter the URL of the page where the matching URL is called. This will open the webpage in a new tab, with a widget showing the status of applied rules.

Modified request bodies will not appear in browser network devtools due to technical constraints but will still be applied to the actual request sent to the server.

Shared State for Advanced Modifications

You can store and retrieve data within and across Modify Request and Modify Response rules using shared state in programmatic JavaScript mode. Learn more about shared state here.

Updated on