Getting Started
Getting Started
Installation
Installation
HTTP Rules (Modify Traffic)
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
Delay Request
Cancel Rule
Organizing Rule
Import/Export Rules from File
Pause/Resume Requestly
Rule Operators
Advance Targeting
Sharing Rules
Map Local
Map Remote
Pinning Rules
GraphQL Support
Edit and Replay
Import Setting from Charles Proxy
Test URL Condition
Test this Rule
File Server
File Server
Sessions Replay
Sessions Replay
Getting Started
Getting Started
Installation
Installation
HTTP Rules (Modify Traffic)
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
Delay Request
Cancel Rule
Organizing Rule
Import/Export Rules from File
Pause/Resume Requestly
Rule Operators
Advance Targeting
Sharing Rules
Map Local
Map Remote
Pinning Rules
GraphQL Support
Edit and Replay
Import Setting from Charles Proxy
Test URL Condition
Test this Rule
File Server
File Server
Â
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.
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
, orÂPath
 withÂRegex
,ÂContains
,ÂWildcard
, orÂEquals
 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 whenÂhoppscotch
 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.
Â