How to mock an API response without changing the server
The AutoResponder answers matching requests itself, so they never reach the server. Use it to test how your app handles an error, a slow response or data the server doesn't send yet. The rules work the same way as Fiddler Classic's.
1. Capture the real response
Start VioLens and use the app until the request you want to mock shows up in the session list. Copy its response body into a file, such as orders.json, and change it however you like.
2. Add a rule
- Check Tools > AutoResponder to show the rules.
- Click Add Rule.
- In Match, enter text from the URL, such as
/api/orders. You can also useEXACT:for the full URL,regex:for a regular expression,NOT:to match everything else, orMETHOD:POST. - In Action, enter the path of your file, such as
C:\mocks\orders.jsonor/Users/you/mocks/orders.json. - Check the box at the start of the row to turn the rule on.
The next time your app requests that URL, it gets your file.
Other things a rule can do
| Action | What happens |
|---|---|
https://other.example.com/... |
Serves another URL’s response instead |
*redir:https://... |
Sends a redirect |
*delay:3000 |
Waits 3 seconds before carrying on, to test a slow server |
*header:Name=Value |
Adds or changes a header |
*drop |
Closes the connection without a response |
*reset |
Resets the connection |
*bpu |
Pauses the request at a breakpoint so you can edit it |
Rules are checked in order and the first match wins, so use Move Up and Move Down when two rules could match. VioLens remembers your rules, but the AutoResponder always starts switched off, so a forgotten rule can’t catch you out.