Introduction
docs.telerik.com: Fiddler's AutoResponder allows you to return files from your local disk instead of transmitting the request to the server.
You can mock response for any request with Fiddler AutoResponder. Let's imagine, You are working in web development and you are dependent on another API, Like, Login service for your front end application, your API may depend on 3rd party service. You need to mock these services to test the negative scenarios.
Even you can mock HTML, CSS and JS files too.
Let's say you fixed a bug in your CSS or JS files in your local but you need to test it with production or staging server without any deployment. Because, deployment takes more time. So you can easily mock your production/staging CSS or JS files with your local files. Cool right.
Installing Fiddler
- Go to https://www.telerik.com/fiddler and download and install fiddler software.
- Open fiddler and go to Tools -> Options from the top menu bar.
- Popup window will appear in the screen. select HTTPS -> Actions -> Reset All Certificates.
- Select OK and YES options for all upcoming the popups.
- Now, Fiddler is ready to mock any request.
Mocking Response
- Click on the AutoResponder tab in the right side pane.
- Select the Enable rules and Unmatched requests passthrough.
- Click Add rule button. Two inputs inside rule editor are enabled to configure.
-
In the rule editor, there are two inputs that will be there.
- First input need to provide the request URL. you can provide a regex pattern to match multiple request URLs or simply provide the Exact URL that needs to be mocked.
- In another input, you can select files from your local by selecting Find File in the dropdown.
- After filling both input, click Save button.
- Here I mocked a CSS file on w3schools website. You can mock any request like this for your development.
API mocking
-
In the rule editor, there are two inputs that will be there.
- First input need to provide the request URL. you can provide a regex pattern to match multiple request URLs or simply provide the Exact URL that needs to be mocked.
- In another input, you can create your response by selecting Create new response in the dropdown.
- After filling both input, click Save button.
- A popup will be appear to create response.
- Select Raw tab and you can edit the headers, response code, response message whatever you want.
- Click Save button and close the popup. Now you can verify the mocked response in your machine anywhere.
- Here I mocked a response for your understanding.
- If you need to edit this response, right click and choose Edit response, then popup will appear, now you can modify the response.