How to mock an API response in Chrome
When the backend isn’t ready, or you need an edge case on demand, Headerbench can answer an
API call with your own JSON. No proxy, no code changes, no patched fetch.
Return your own JSON
- Install Headerbench and create a profile named Mocks. Mocks are a Pro feature; the 14-day trial starts when you save your first one, with no card.
- Open Mocks and add a rule with the pattern
||api.example.com/v1/users^. - Set the content type to
application/jsonand the body to{"users":[{"id":1,"name":"Ada Lovelace"}]}. - Open your app, turn the profile on in the popup and allow access to
api.example.comand your app’s page when Chrome asks. - Reload your app.
fetch('https://api.example.com/v1/users')now returns your body. - Use Test a URL to check which URLs the pattern catches, for example
that
/v1/users/42is not one of them.
Limits to know
-
Chrome serves the mock as a redirect to a
data:URL, so the status is always 200 and the real server’s headers are not sent. - Bodies can be up to 64 KB.
- Mocks apply to fetch/XHR, scripts, stylesheets, images, fonts and media, not to page or iframe navigations.
-
For error statuses or delays, use a local mock server or a tool that patches
fetchin the page, such as Requestly.
Install Headerbench
Free, no account, no tracking. Pro is optional.
The Chrome Web Store and Edge Add-ons listings are on their way. Install links appear here as soon as they are live.