The Rules feature in HttpTracer is one of the most powerful tools for developers who want to intercept and modify network traffic on the fly. Whether you're debugging API responses, testing error handling, or simulating different server behaviors, Rules gives you full control over HTTP requests and responses.
In this guide, we'll walk you through everything you need to know to get started with Rules.
What Are Rules?
Rules allow you to:
- Match specific network requests based on URL, method, headers, query parameters, and more
- Modify requests before they're sent to the server (change headers, query params, redirect to a different URL)
- Modify responses before they reach your app (change status codes, headers, or even replace the entire response body)
This is incredibly useful for:
- π Debugging: Test how your app handles different API responses without changing server code
- π§ͺ Testing edge cases: Simulate 500 errors, slow responses, or unexpected data
- π Mocking APIs: Return custom responses for endpoints that don't exist yet
Getting Started with Rules
Step 1: Open the Rules Editor
Click on the Rules tab in the sidebar to open the Rules Editor.
You'll see a three-panel interface:
- Left Panel: Rule Groups and Rules tree
- Center/Right Panel: Rule configuration (Matchers and Actions)
Step 2: Create a Rule Group
Rules are organized into Groups for better organization. Think of groups as folders for your rules.
- Click the "+ Group" button in the left panel
- A new group called "New Group" will appear
- Double-click the group name to rename it (e.g., "API Debugging Rules")
Step 3: Add a Rule
With your group selected:
- Click the "+ Rule" button or right-click the group and select "Add Rule"
- A new rule called "New Rule" will be created
- Click on the rule to select it and start configuring
Configuring Your Rule
Every rule has two main parts:
- Matchers - Define WHICH requests/responses this rule applies to
- Actions - Define WHAT to do with matched traffic
Matchers: Targeting Specific Traffic
The Matchers section lets you specify which network requests should be affected by this rule.
Available Request Matchers:
| Matcher | Description | Example |
|---|---|---|
| Method | HTTP method (GET, POST, etc.) | Match only POST requests |
| Protocol | HTTP or HTTPS | Match only HTTPS requests |
| URL | Full URL matching | Match api.example.com/users
|
| Hostname | Just the domain | Match api.example.com
|
| Path | URL path only | Match /api/v1/users
|
| Headers | Request headers | Match requests with Authorization header |
| Query Params | URL query parameters | Match requests with ?debug=true
|
Matching Conditions:
Each matcher supports different conditions:
- equals - Exact match
- contains - Partial match
- starts-with - Match beginning
- ends-with - Match ending
- regex - Regular expression pattern
- not-equals - Inverse match
Example: To match all GET requests to api.example.com:
- Set Method to
GET - Set Hostname condition to
equalswith valueapi.example.com
Actions: Modifying Traffic
Once you've defined what traffic to match, you can specify what to do with it.
Modify Request Actions:
Enable "Modify Request" to change the request before it's sent:
- Change Method: Switch GET to POST, etc.
- Change URL/Hostname/Path: Redirect requests to different servers
- Add/Remove/Edit Headers: Add authentication, modify content types
- Add/Remove/Edit Query Params: Inject or remove URL parameters
Modify Response Actions:
Enable "Modify Response" to change the response before your app receives it:
- Change Status Code: Return 200, 404, 500, etc.
- Add/Remove/Edit Headers: Modify CORS headers, caching, etc.
- Override Body: Return custom JSON, HTML, or load from a file
Practical Examples
Example 1: Simulate an API Error
Goal: Test how your app handles a 500 server error from /api/users
- Create a new rule
-
Matchers:
- Path:
containsβ/api/users
- Path:
-
Actions:
- Enable "Modify Response"
- Set Status Code to
500 - Optionally set body to
{"error": "Internal Server Error"}
Now any request to /api/users will return a 500 error!
Example 2: Add Debug Headers
Goal: Add a custom header to all API requests
- Create a new rule
-
Matchers:
- Hostname:
containsβapi.
- Hostname:
-
Actions:
- Enable "Modify Request"
- Add Header:
X-Debug-Mode=true
All requests to domains containing "api." will now include your debug header.
Example 3: Mock an API Response
Goal: Return fake data for an endpoint that doesn't exist yet
- Create a new rule
-
Matchers:
- Path:
equalsβ/api/v2/new-feature
- Path:
-
Actions:
- Enable "Modify Response"
- Set Status Code to
200 - Set Body to:
{
"feature": "enabled",
"data": ["item1", "item2", "item3"]
}
Tips & Best Practices
1. Use Rule Groups Effectively
Organize your rules by project, feature, or purpose. You can enable/disable entire groups at once.
2. Toggle Rules On/Off
Each rule has an active toggle. Disable rules you're not currently using without deleting them.
3. Use Regex for Complex Matching
Need to match /users/123 and /users/456? Use regex: /users/\d+
4. Test with Live Traffic
Open the Live panel alongside Rules to see your modifications in real-time.
5. Duplicate Rules
Right-click a rule to duplicate it β great for creating variations of existing rules.
Troubleshooting
Rule Not Working?
- Check if the rule is active - Look for the toggle switch
- Check if the group is active - Groups can also be disabled
- Verify your matchers - Make sure the conditions actually match your traffic
- Check the order - Rules are processed in order; earlier rules take precedence
Need More Power?
Consider upgrading your plan to create more rule groups and rules per group.
Summary
The Rules feature transforms HttpTracer from a simple traffic viewer into a powerful debugging and testing tool. By setting up the right matchers and actions, you can:
- β Test error handling without changing server code
- β Mock APIs during development
- β Debug complex request/response flows
- β Simulate edge cases and rare scenarios
Start with simple rules and gradually explore more advanced features like regex matching, header manipulation, and response body overrides.
Happy debugging with HttpTracer π




Top comments (0)