Cancel Request Rule is a feature used to block network requests, allowing users to avoid distractions or test specific error scenarios effectively. This guide explains how to configure and utilize the Cancel Request Rule in your workflow.
Why Use Cancel Request Rule?
-
Blocking Distracting Websites: Leverage the Cancel Rule to block access to websites such as YouTube, Twitter, or Facebook to stay focused. Set the source condition to match the URLs of these websites and enable the rule.
-
Testing Error Scenarios: Simulate real-world application behaviors when resources are unavailable. For example, block a specific non-critical API request and observe how your application handles the missing resource.
How to Configure Cancel Rule
Open HTTP Rules and Create a New Rule
Navigate to the HTTP Rules section in your application and click on the + New Rule
button. From the available options, select Cancel Rule
to begin configuration.
Name and Describe Your Rule
Provide a descriptive name and an optional description for your Cancel Rule. This helps keep your rules organized and ensures clarity when managing multiple rules.
Define the Source Condition
Source Condition specifies the criteria for matching requests. You can target requests using the following attributes:
-
URL, Host, or Path: Define what part of the request should be matched.
-
Operators: Choose from Regex, Contains, Wildcard, or Equals to apply precise matching logic.
For more detailed guidance, refer to the Source Conditions Guide.
Example: Let’s try to block product listing API call on https://www.requestly-playground.com/
Apply Source Filters
Filters refine the targeting of Cancel Rules by adding additional constraints. Filters can be based on:
-
Webpages or domains
-
Request types (e.g., XHR, Fetch, etc.)
-
HTTP methods (e.g., GET, POST)
-
Request payload attributes
For more information, explore the Source Filters Guide.
For this example we will leave it intact.
Save and Activate the Rule
Once you have configured the conditions and filters, save the rule and toggle it on to activate. This ensures that the rule applies immediately to the specified requests.
Test the Rule
To ensure the rule is working correctly, click the Test
button and enter the URL of the page where the matching URL is called. This will open the webpage in a new tab, with a widget showing the status of applied rules.
On loading the https://www.requestly-playground.com/
website, it shows network error. A small widget on the page confirms that the Rule is applied. You can click on View Results button to view the result details.