Different Rule Types in Requestly
Tags: webdev
Published: 2022-12-26 21:39:35

[Requestly](https://requestly.com/) is a lightweight proxy available as a browser extension & desktop app to intercept & modify network requests. We bundle powerful tools to do a lot more with network requests than ever, such as Mocking API Responses, Modifying Headers, Redirecting URLs, Delay/Throttle requests, and much more. This article will explain the different rule types available in Requestly and the different use cases for each rule type.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yepf720ma97ifb5afnww.png)



There are currently 10 rule types available in Requestly :-

## Redirect Network Requests

Redirect Rule is used to redirect one URL to another URL. Example of common use cases could be:

1. Test API version changes: Suppose there is a new version of some API which you are using. In order to test the backward compatibility of the API, you can just set up a redirect rule to redirect all URLs from older version to newer version and check if your application behaves as expected. This way, you don’t need to change single line of your code and test the API upgrades.

2. Fix Broken Urls, Redirect dead bookmarks, and Create URL shortcuts: You can setup redirect rule to fix some broken rules, redirect the dead bookmarks to new working bookmarks and create URL shortcuts.

There can be many more examples like these but the above two examples give you an idea of where you can use the Redirect Rule.

{% youtube lOt1kGKTq-w %}


## Cancel/Block Network Requests

Cancel Rule is primarily used for Blocking Requests therefore it is alternatively called as Blocker Rule as well. Primary use cases include:

1. Blocking Websites — You can use Cancel Rule to block social media websites to stay focussed.

2. Test your app when certain resource is not loaded — You can use Cancel rule to block a certain request which is not mandatary in your app and test how your app behaves without that resource.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhftujk899bmi5z4ge63.png)

## Modify Headers
Headers Rule is used for modifying request and response headers. There are not many extensions available in Chrome Store and Firefox Store which allow you to modify response headers. Some use cases are:

1. Bypass Iframe Buster Header: Most websites use X-Frame-Options header to prevent opening inside iframe. However, a developer may want to open the website inside iframe for debug/demo purposes. [This article](https://www.requestly.in/content/articles/iframe-busting-header/) explains how you can do that using Header Rule.

You can setup Header rule to modify Request and Response headers according to your use cases. This rule is mostly used by developers and is the most used rule in Requestly as per Google Analytics. Have a look at [list of headers](https://medium.com/@requestly_ext/list-of-headers-not-allowed-to-be-modified-by-chrome-extensions-c850b5c02fff) not allowed for modification.

{% youtube CLEHS6NFYZY %}


## Modify API Response

Requestly provides Modify API response option using which you can modify the response body of APIs. Helpful in debugging APIs directly on production (or live) sites.Similar to other Rules, this Rule will also allow you to specify advanced filters including the regular expressions. Some use cases are:

1. Test AJAX response without actually modifying backend
2. Mock fluctuating responses.
3. Mock response to focus on front-end development even if back-end is not available.

{% youtube KIPbxUGUYq8 %}

## Inject custom javascript (Code or from URL)

[Script Rule](https://medium.com/@requestly_ext/inserting-scripts-dynamically-in-a-webpage-be4af90da20a) is very handy and powerful. It allows you to inject custom scripts on a website. You can write custom code (Upto 500 characters) or use [Requestly Library](https://medium.com/@requestly_ext/requestly-file-library-ee9017aabb09) to host your code and use the url inside script rule. It also allows you to pick when should the script be executed before page load or after page load.

{% youtube 4dvucRjLwGY %}

## Modifying QueryParams Rule

QueryParams Rule, as the name suggests is used for modification of Query parameters in a request. You can perform these operations:

- Add Parameter
- Remove given parameter
- Remove all parameters

QueryParams rule can be used to debug/test how the site behaves with different/unwanted query params. You can also use Query Params and apply random query parameter to each request and it will serve as cache buster.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcgsuw9n2su8i6qmzeao.png)


## Replace Strings in URL

As the name indicates, Replace String allows users to replace a string (or matching pattern) with another string in the url. It looks to be very simple but it can achieve very complex use cases:

- Switch Domains
- Change Query Parameter Values
- Fix broken/updated URLs
- Pattern Matching in Replace Rule

{% youtube 3esnRDWUBdU %}

## Delay Network Requests

Many times, testing certain parts of web applications require you to simulate a delay in one or more components of the web app. Here are some scenarios where you would like to delay the network requests:

- Test performance of your web app on a slower condition
- Test behaviour of your app when one or more APIs respond slow (API Latency has gone up)
- Check if any race conditions exist when some resource X gets loaded after/before another resource Y.
- Test the impact of slow loading of external resources impact on your app.
- Test your loading experience in the app.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8sp8ksuobv3z9ebc5yb.png)

## Override User-Agent Rule

UserAgent Rule is used to modify user agent on a given website and all the urls in that website. Internally, it just modifies the request header and overrides the navigator.userAgent at client side.

1. Cross Browser Testing: UserAgent rule can be used to check how your website behaves when passed different user agents. For example :- You may have done browser specific coding based on user agent. You can use the rule to test that functionality instead of switching between browsers.

2. Test Responsiveness of website: You can set user agent of mobile device and see how the website adapts to the user agent for the mobile device.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h26w3r94lzaxbrdtm1dy.png)

Requestly runs on all [your favorite devices](https://requestly.com/downloads). Requestly makes developing and debugging easier!

Hope this article gives you a nice overview of the power behind the simplicity in Requestly. Feel free to drop a comment if you have any questions. You can also reach out to us at Contact@requestly.io for any extension-related suggestions or feedback. We respond to each and every query from our users.