Getting Started
Getting Started
Installation
Installation
Inspect Traffic
Inspect Traffic
HTTP Rules (Modify Traffic)
HTTP Rules (Modify Traffic)
Overview
Request Modification — Redirect URL (Map Local, Map Remote)
Request Modification — Replace Strings (Switch Hosts, API Endpoints)
Request Modification — Modify Headers
Request Modification — Modify Request Body
Response Modification — Modify Response Body
Request Modification — Modify Query Params
Request Modification — Modify User Agents
Request Modification — Delay Request
Request Modification — Map Local
Request Modification — Map Remote
Response Modification — Modify DOM/Inject scripts
Response Modification — Cancel Rule
Predefined Functions
Organizing Rule — Grouping
Organizing Rule — Import/Export Rules from File
Organizing Rule — Pause/Resume Requestly
Organizing Rule — Rule Operators
Organizing Rule — Advance Targeting
Organizing Rule — Sharing Rules
Organizing Rule — Pinning Rules
GraphQL - Modify Request & Response
Import / Export — Charles Proxy Rules
Test Rules — Test URL Condition
Test Rules — Test this Rule
Session Book
Session Book
File Server
File Server
Public API
Public API
FAQ
FAQ
Guides
Guides
TroubleShooting
TroubleShooting
Subscription & Billing
Subscription & Billing
Getting Started
Getting Started
Installation
Installation
Inspect Traffic
Inspect Traffic
HTTP Rules (Modify Traffic)
HTTP Rules (Modify Traffic)
Overview
Request Modification — Redirect URL (Map Local, Map Remote)
Request Modification — Replace Strings (Switch Hosts, API Endpoints)
Request Modification — Modify Headers
Request Modification — Modify Request Body
Response Modification — Modify Response Body
Request Modification — Modify Query Params
Response Modification — Modify DOM/Inject scripts
Request Modification — Modify User Agents
Request Modification — Delay Request
Response Modification — Cancel Rule
Organizing Rule — Grouping
Organizing Rule — Import/Export Rules from File
Organizing Rule — Pause/Resume Requestly
Organizing Rule — Rule Operators
Organizing Rule — Advance Targeting
Organizing Rule — Sharing Rules
Request Modification — Map Local
Request Modification — Map Remote
Organizing Rule — Pinning Rules
GraphQL - Modify Request & Response
Import / Export — Charles Proxy Rules
Test Rules — Test URL Condition
Predefined Functions
Test Rules — Test this Rule
File Server
File Server
Public API
Public API
Sessions Replay
Sessions Replay
Guides
Guides
Session Book
Session Book
Subscription & Billing
Subscription & Billing
Modify Request 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.
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.
- Source Condition: Source condition is where you set criteria for the rules. You can use
URL
,Host
, orPath
withRegex
,Contains
,Wildcard
, orEquals
to match the source request. Learn more about source conditions here.
- Static Request Body: Define the static request body which must be passed to the server.
- 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.
Programmatic Modification Script (JS) is where you write a JavaScript script that can modify the existing request body programmatically.
Arguments of modifyRequestBody
method
(string)- The HTTP method of the request.GET | POST | PUT | DELETE etc.
url
(string) - The request URL.
body
(string)- The original request body stringified:
'{"app":"requestly","feature":"modify-request"}'
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.- 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));
- 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; }
- You can see the key
feature
being added to the request body whenhoppscotch
echoes back the request.
Popular Use Cases:
- Primarily used in sending additional data in request payload to the API server: There might be situations where additional data needs to be sent in request payloads to the API server when making a POST or PUT request.
- Modifying GraphQL Queries: GraphQL queries can be modified by modifying the request body of the request. This can be done by changing the query string or variables in the request body.
- Testing different edge cases: You may modify an API request payload to include an invalid or unsupported field. The server will likely reject the API request and return an error message.
FAQs
Request Rule not working
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.