<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[RequestFox]]></title><description><![CDATA[Practical notes for testers and web developers: how to record real API calls, mock a response, replay a request and catch the bugs the Network tab hides. Writte]]></description><link>https://requestfox.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6aeccfce776826235e8f00fe/cb0476f2-6a3f-4201-b345-daee6ea59ec4.png</url><title>RequestFox</title><link>https://requestfox.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 22:46:56 GMT</lastBuildDate><atom:link href="https://requestfox.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[4 ways to mock an API response in the browser (without touching the backend)]]></title><description><![CDATA[Four ways to fake an API response in the browser: DevTools overrides, MSW, a console fetch patch or an extension, and when to use each.]]></description><link>https://requestfox.hashnode.dev/4-ways-to-mock-an-api-response-in-the-browser-without-touching-the-backend</link><guid isPermaLink="true">https://requestfox.hashnode.dev/4-ways-to-mock-an-api-response-in-the-browser-without-touching-the-backend</guid><category><![CDATA[Web Development]]></category><category><![CDATA[api]]></category><category><![CDATA[Testing]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[chrome extension]]></category><category><![CDATA[Firefox]]></category><category><![CDATA[APIs]]></category><category><![CDATA[requestfox]]></category><dc:creator><![CDATA[RequestFox]]></dc:creator><pubDate>Fri, 27 Nov 2026 09:35:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6aeccfce776826235e8f00fe/c03ab7d8-f756-4892-909f-a6c226a8849a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A while ago, someone gave our Chrome extension a 1-star review.</p>
<p>The reason?</p>
<p>They couldn't figure out how to mock an API response.</p>
<p>Now, here's the interesting part: the feature already existed. It just wasn't easy enough to find.</p>
<p>And honestly, that feedback was fair.</p>
<p>When you're building a developer tool, it's easy to assume that people will figure things out because you know exactly where everything is. But users don't have that context. They just want to get their work done.</p>
<p>That review made us rethink how we were approaching API mocking.</p>
<p>We started looking more closely at the different ways developers mock API responses directly in the browser. Some approaches are surprisingly simple. Others offer much more control but require additional setup.</p>
<p>So, if you've ever wanted to test how your frontend behaves when an API returns a 500, sends unexpected data, or simply takes too long to respond, here are four ways worth knowing.</p>
<p>No backend changes required.</p>
<h2>1. Chrome DevTools Local Overrides</h2>
<p>Let's start with something you probably already have.</p>
<p>Chrome DevTools.</p>
<p>Most developers know Local Overrides for changing CSS or JavaScript files. But you can also use them to modify network responses, including Fetch and XHR responses.</p>
<p>Here's how:</p>
<ol>
<li>Open Chrome DevTools.</li>
<li>Go to the <strong>Network</strong> tab.</li>
<li>Filter requests using <strong>Fetch/XHR</strong>.</li>
<li>Trigger the API call you want to modify.</li>
<li>Right-click the request and select <strong>Override content</strong>.</li>
<li>Select a local folder when Chrome asks for permission.</li>
<li>Edit the response and save it.</li>
<li>Trigger the request again.</li>
</ol>
<p>That's it.</p>
<p>Chrome will use your local version of the response instead of the original one.</p>
<p><strong>When is this useful?</strong></p>
<p>Imagine you're testing a user profile page and want to see what happens when the API returns an empty profile.</p>
<p>You don't need to change anything on the server. Just modify the response locally and reload the relevant flow.</p>
<p><strong>What I like:</strong> It's already available in Chrome, doesn't require another extension, and gives you direct control over the response.</p>
<p><strong>What's not so great:</strong> Your overrides are stored as local files. If you forget that an override is active, you might spend time debugging behaviour that isn't coming from the actual API.</p>
<p>For quick experiments, though, it's a pretty handy option.</p>
<h2>2. Mock Service Worker (MSW)</h2>
<p>Now, if you're working on your own frontend application and want something more organised, take a look at Mock Service Worker.</p>
<p>Unlike DevTools overrides, MSW lets you define API mocks in your application code.</p>
<p>It uses a Service Worker in the browser to intercept requests and return the responses you've defined.</p>
<p>For example:</p>
<pre><code class="language-javascript">import { http, HttpResponse } from 'msw';
import { setupWorker } from 'msw/browser';

const worker = setupWorker(
  http.get('/api/cart', () =&gt;
    HttpResponse.json({
      items: [],
      total: 0
    })
  ),

  http.post('/api/checkout', () =&gt;
    new HttpResponse(null, { status: 500 })
  )
);

await worker.start();
</code></pre>
<p>Here, we're doing two things:</p>
<ul>
<li>Returning an empty cart when <code>/api/cart</code> is called.</li>
<li>Returning a 500 status when the checkout API is called.</li>
</ul>
<p>You can define different responses for different scenarios without changing your actual backend.</p>
<p>The bigger advantage is that these mocks can live alongside your application code. Your team can share them, review them and reuse them in automated tests.</p>
<p><strong>When is this useful?</strong></p>
<p>When multiple developers are working on the same frontend and the backend isn't ready yet.</p>
<p>Instead of everyone creating their own temporary mocks, the team can work with a shared set of API responses.</p>
<p><strong>What's not so great?</strong></p>
<p>You need access to the application code and a development setup.</p>
<p>If you're testing a website you don't own, MSW isn't going to be the easiest option.</p>
<h2>3. Override Fetch Directly From the Browser Console</h2>
<p>Sometimes you don't want to install anything.</p>
<p>You don't want to configure a library.</p>
<p>You just want to change one API response and see what happens.</p>
<p>For that, you can override <code>window.fetch</code> directly from the browser console.</p>
<p>Here's a simple example:</p>
<pre><code class="language-javascript">const realFetch = window.fetch;

window.fetch = async (input, init) =&gt; {
  const url = input instanceof Request
    ? input.url
    : String(input);

  if (url.includes('/api/cart')) {
    return new Response(
      JSON.stringify({ items: [] }),
      {
        status: 200,
        headers: {
          'Content-Type': 'application/json'
        }
      }
    );
  }

  return realFetch(input, init);
};
</code></pre>
<p>What's happening here?</p>
<p>We're saving the original <code>fetch</code> function and replacing it with our own version.</p>
<p>Whenever the page requests <code>/api/cart</code>, we return our custom response.</p>
<p>For every other request, the original Fetch function handles it.</p>
<p>Pretty simple.</p>
<p><strong>When is this useful?</strong></p>
<p>When you want to quickly test a UI state without setting up a dedicated mocking tool.</p>
<p>For example, you could return an empty array to check how your application handles an empty search result.</p>
<p><strong>But there's a catch.</strong></p>
<p>This approach is temporary.</p>
<ul>
<li>Refresh the page, and your changes disappear.</li>
<li>It only intercepts Fetch requests, not XMLHttpRequest.</li>
<li>Requests already made before you run the script won't be affected.</li>
<li>Other scripts can potentially overwrite your modification.</li>
</ul>
<p>It's a useful trick, but I wouldn't build my regular testing workflow around it.</p>
<h2>4. Mock an API Call You've Already Recorded</h2>
<p>This is where things get a little more interesting.</p>
<p>What if you could simply open a website, let it make its normal API calls, pick the request you want to change, and create a mock from that actual request?</p>
<p>That's the approach we wanted to make easier with RequestFox.</p>
<p>And it's also the feature that led us back to that 1-star review.</p>
<p>With RequestFox 2.5.0, every recorded API call has a <strong>Mock</strong> button.</p>
<p>The workflow is simple:</p>
<ol>
<li>Install RequestFox for <a href="https://chromewebstore.google.com/detail/requestfox-network-qa-mon/lbhhldlnlgceobhpmpkljbefpiilhgmb">Chrome</a> or <a href="https://addons.mozilla.org/firefox/addon/requestfox-network-qa-monitor/">Firefox</a></li>
<li>Press <strong>Start Recording</strong>.</li>
<li>Open your application and trigger the API request.</li>
<li>Find the request in RequestFox.</li>
<li>Press <strong>Mock</strong>.</li>
<li>Change the response status or body.</li>
<li>Press <strong>Mock it</strong>.</li>
<li>Reload your application and test again.</li>
</ol>
<p><em>Press Mock on a call, change the status or the body, and press Mock it.</em></p>
<p>The idea is to start with a real API call instead of writing a mock from scratch.</p>
<p>You can also create different scenarios using rule modes:</p>
<ul>
<li><strong>Custom status:</strong> Make an API return a status code such as 400, 401 or 500.</li>
<li><strong>Drop connection:</strong> Simulate a request that never gets a normal response.</li>
<li><strong>Add delay:</strong> Test how your application behaves when the API is slow.</li>
<li><strong>Pause:</strong> Stop the request temporarily so you can edit it before it continues.</li>
</ul>
<p>One detail worth mentioning: a mock is associated with the recorded call it was created from.</p>
<p>When recording stops, the mock shows as paused. It can respond again during the next recording, or you can keep mocking enabled for a site without actively recording.</p>
<p>The card also displays a <strong>Mocked</strong> status, making it easier to distinguish modified responses from real API responses.</p>
<p>You can find the complete walkthrough here:</p>
<p><a href="https://requestfox.accessisight.com/guide-mock-api-response.html">How to Mock an API Response in Chrome</a></p>
<p>And if you'd rather watch than read, here's a short video showing the process:</p>
<p><a href="https://www.youtube.com/watch?v=aD3I4vhHqAE">Watch the 20-second walkthrough</a></p>
<p><strong>What we like about this approach:</strong> You start with an actual recorded request, don't have to write JSON from scratch, and can reuse your mock across page reloads.</p>
<p><strong>What you should know:</strong> It requires installing an extension and currently supports requests made through Fetch and XMLHttpRequest.</p>
<p>It's not meant to replace every mocking solution. It's simply another way to make browser-based API testing less complicated.</p>
<h2>So, Which Approach Should You Actually Use?</h2>
<p>Honestly, there isn't one answer.</p>
<p>It depends on what you're trying to test and how often you'll need to repeat it.</p>
<p>Here's how I'd choose:</p>
<table>
<thead>
<tr>
<th>Your situation</th>
<th>What I'd use</th>
</tr>
</thead>
<tbody><tr>
<td>Quickly change a response on a website</td>
<td>Chrome DevTools</td>
</tr>
<tr>
<td>Share mocks across a development team</td>
<td>MSW</td>
</tr>
<tr>
<td>Make a temporary change without installing anything</td>
<td>Console Fetch override</td>
</tr>
<tr>
<td>Modify an API call you've already recorded</td>
<td>RequestFox</td>
</tr>
</tbody></table>
<p>And if you're testing error scenarios, slow responses or empty states, all four approaches can help. The right choice depends on your existing workflow.</p>
<h2>One Last Thing</h2>
<p>That 1-star review we mentioned at the beginning?</p>
<p>We could have dismissed it as a user who didn't understand the feature.</p>
<p>But that wouldn't have solved anything.</p>
<p>The feature wasn't easy to discover, and that was our problem to fix.</p>
<p>I think there's a lesson here for anyone building developer tools: a feature isn't really useful just because it exists. People should be able to find it, understand it and use it without needing someone to explain it.</p>
<p>We're still improving RequestFox, and we'd genuinely like to know how other developers approach API mocking.</p>
<p><strong>Is there another way you mock API responses in the browser that we haven't covered?</strong></p>
<p>Tell us in the comments. We'd love to learn something new.</p>
<hr />
<p><em>Written with AI help and checked by me before posting. Disclosure: we build RequestFox.</em></p>
]]></content:encoded></item></channel></rss>