Understanding HTTP Rules – Intercept & Modify HTTP Requests & Responses

Before diving deeper into the HTTP Rules, it’s essential to understand what Requests/Responses are. It is crucial for effectively utilizing HTTP Rules in Requestly.

Content Overview

What are HTTP Request & Response?

An HTTP transaction consists of two main components: a Request sent by the client and a Response sent by the server. A Request is data sent to a server, which processes the information. The server processes the request and generates a corresponding response. The server retrieves or generates the requested data and creates a response consisting of a status code, headers & body.

HTTP Request Response

This is the simplest explanation of Request & Response. Now as a developer or tester, you might want to modify these requests and responses for various use cases during development. Requestly enables modification of header, path, query parameters, status codes & body of Request & Response.

Request Modification Rules

During development, there are multiple use cases where we want to modify our requests on the fly. Here are some of the common use cases:

  • Change the request body to test a special edge case causing the bug.
  • Add a new header to request, to get a different type of response from the server.
  • Change query parameters to test a filter in a query not yet implemented on UI.
  • JS/CSS version change by changing query parameters
  • Change the authorization header value to pass the authentication or log in as a different user.
  • Apply local non-minified version of JS/CSS on prod for debugging.
  • Apply local modified JS/CSS on production to test its working on prod.
  • Test Production frontend service with local backend APIs or vice-versa.
  • Check browser-specific modifications like changes for Safari on Windows machines.
  • Simulate slow network response for performance testing.

HTTP Rules in Requestly simplifies handling these use cases with its user-friendly interface. It enables you to define these modifications in terms of rules and these rules make changes to the requests on the fly on your local system. Requestly has multiple rule types for each use case:

  1. Redirect Rule – Doc
  2. Replace Rule – Tutorial
  3. Modify Request Headers – Doc
  4. Modify Query Parameters – Doc
  5. Modify Request Body – Tutorial
  6. Modify User Agents – Doc
  7. Delay Requests – Doc
  8. Map Local – Doc
  9. Map Remote – Doc

Response Modification Rules

Along with Request modification rules, frontend developers and testers often need to modify the response of a request for various use cases. Here are some of the common use cases for response modification:

  • Remove Content Security Policy to inject scripts.
  • Debug CORS issue by modifying response headers like  Access-Control-Allow-OriginAccess-Control-Allow-MethodsAccess-Control-Allow-Headers  and  Access-Control-Allow-Credentials .
  • Work on front-end while back-end is not available or ready yet.
  • Test application behavior when provided with altered data.
  • Simulate errors by returning different status codes.
  • Modify API responses but don’t have access to the back-end.
  • Inject popular libraries or hosted scripts or execute custom code snippets before or after page load.
  • Testing error scenarios – Test an app when a certain resource is not loaded and see how app behaves without that specific resource.

Response medication HTTP rules like Modify Header, Modify Response Body, Insert Script, and Cancel Rules, enable you to define these modifications precisely. Requestly applies these rules in real-time, enabling on-the-fly changes to responses directly on your local system. Below are the HTTP Rules to modify responses:

  • Modify Response header – Doc
  • Modify Response Body – Tutorial
  • Insert Script – Tutorial
  • Cancel Rule – Doc

Hope this overview has given you a clear understanding of how Requestly can enhance your workflow. In upcoming articles, we will dive deeper into each rule and provide a detailed guide, how-to videos, and use cases for each rule.

This article was written by:

Picture of Abhishek Sachan

Abhishek Sachan

Abhishek is Growth Engineer at Requestly and has profound love for programming.

Share this article:

You may also like