The Modify API Response Rule in Requestly allows developers to modify API responses directly without requiring back-end access. It is often used to simulate edge cases, replicate bugs, and support QA workflows. With Dynamic Modification, developers can use JavaScript to conditionally alter responses based on the original request or server response
Why Use Modify API Response Rule?
Modify API Response Rules are useful in several scenarios:- Frontend Development: Work seamlessly even if the backend is unavailable or incomplete.
- Custom Testing: Test application behaviour with modified or custom data.
- Error Simulation: Trigger specific errors by modifying response status codes.
- Backend Independence: Make changes to API responses without requiring backend changes.
Steps to Configure a Modify API Response Rule
1
Create a Response Rule
Navigate to the HTTP Rules section in the Requestly app. Click 
+ New Rule and choose the Modify API Response option.
2
Select Resource Type
Choose the resource type for modification:
-
REST API: Modify
XHR/Fetchrequests initiated by web pages. - GraphQL: Target and modify GraphQL APIs by operation.
- HTML/JS/CSS (Desktop App Only): Modify static files for desktop applications.

3
Define Matching Criteria
Define the criteria for the rule to be applied, such as URL, Host, or Path. Choose from Regex, Contains, Wildcard, or Equals, or use Advance Filters for more precise conditions.For more detailed guidance, refer to the Source Conditions Guide.

4
Filter GraphQL Queries (Optional)
If targeting GraphQL APIs, filter queries by their operation name. Add the Payload JSON Key (e.g., 
operationName) and specify the corresponding Value (e.g., getUsers) to target specific GraphQL operations.
5
Change Response Status Code
Modify the status code of the response using the dropdown menu. Choose from:
-
2XXfor successful responses -
4XXfor client errors -
5XXfor server errors

6
Modify Response Data
Choose one of the following methods to modify the response data:
- Static Response Modification: Input a static value as the response body.
-
Dynamic Modification Script (JavaScript): Use JavaScript to modify responses dynamically. The script provides access to parameters like:
-
method: HTTP Method (GET, POST, etc.) -
url: Full URL of the request -
response: Original response body (string) -
responseType: Content type of the original response -
requestHeaders: Headers sent with the request -
responseJSON: Original response parsed as a JSON object
-
Desktop App feature
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.
→Learn more about shared state here.
7
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.

8
Test the Rule
To ensure the rule is working correctly, click the 
Test button and enter the URL of the page where you want to apply this rule. This will open the webpage in a new tab, with a widget showing the status of applied rules.




