Response Modification — Modify Response Body

Getting Started
Installation
Setup
Inspect Traffic
HTTP Rules (Modify Traffic)
Session Book
Mock Server
API Client
File Server
Workspace
Public API
Guides
TroubleShooting
Subscription & Billing
Getting Started
Installation
Setup
Inspect Traffic
API Client
HTTP Rules (Modify Traffic)
Mock Server
File Server
Workspace
Public API
Guides
Session Book
Subscription & Billing
TroubleShooting

Modify Response Body

The Modify Response Rule allows you to mock the response body of an HTTP request.
 
Video preview

Popular use cases

  • You want to work on front-end while back-end is not available or ready yet.
  • You want to test application behaviour when provided altered data.
  • You want to simulate errors by returning different status codes.
  • You want to modify API responses but don't have access to the back-end.

Options

  1. Select Resource Type
    1. notion image
    2. REST API: To modify XHR/Fetch requests from web pages.
    3. GraphQL: To Target & Modify GraphQL APIs using operations.
    4. HTML/JS/CSS(Desktop app only) - To work with HTML/JS/CSS files.
  1. Source Condition: If the request URL matches this source condition, then only the rule is applied. You can use URLHost, or Path with Regex, Contains, Wildcard or Equals to match the source request. Learn more about source conditions here.
  1. Source Filters: This helps you define better targeting conditions and restrict rules to be applied on specific webpages (or domains), request types, request methods, or request payloads. Learn more about source filters here.
  1. GraphQL Operation(only in the case of GraphQL) - Enables matching the operation you want to target in case of GraphQL APIs.
  1. Response Status Code: Update the Response status code. (2XX, 3XX, 4XX, 5XX ...). If left empty, the original status code is returned.
  1. Response Body
    1. Static Response Modification - In this mode, you can enter the response body that you want as the response.
      1. notion image
    2. Programmatic Modification Script (JS) - Write a JavaScript script that can modify the existing response programmatically. The following arguments are available to create a response programmatically:
      1. notion image
      2. method (string)- HTTP Method of the request like - GET, POST, PUT, DELETE, PATCH
      3. URL (string)- Complete the URL of the request including query parameters.
      4. response (string) - Original response body as a string.
      5. responseType (string) - The content type of the original response.
      6. requestHeaders (Object) - The request headers are sent to the server.
      7. requestData (string) - The HTTP request payload in case of POST, PUT & PATCH requests.
      8. responseJSON (JSON object)- The original response body as a JSON Object.
      9. ✏️
        Response Returned (JSON or String) - A new response can be generated in string or JSON format, Requestly can handle both responses.
    3. Local File(Desktop App Only) - In case you have your response in a file, browse the file and its content will be returned.
  1. Test this rule - This box will appear only after you save the rule, it accepts a URL and opens it in a new tab for you to test. It comes with an option to capture screen, console & network details, if enabled Requestly will capture these details in SessionBook for debugging later.

Targeting GraphQL requests

You can target GraphQL requests using the operation name in request body. To do so add:
  • Payload JSON Key, e.g., operationName
  • Value, e.g., getUsers
    • notion image
To learn more about this checkout GraphQL Support.

Guides

 

FAQs

What happens if I leave the status code field empty
If you leave the status code empty, then the original status code of the request is returned.
Where would console.log show up?
TODO