Skip to content
Mittelware

Documentation

Learn Mittelware

Everything you need to go from first launch to confident rule-writing.

Modify Response

Change the status code, headers or body of a response before your app receives it, or answer instead of the server, to mock an API, fake an error, return unusual data or test a fix without touching the server.

Modify Response changes the answer your app gets. It works in one of two ways, chosen in its Behavior box:

  • Instead of the server: Mittelware answers the request itself and the real server is never contacted. This is what a new rule starts with, and it has its own page: Answer without the server.
  • After the server responds: the request goes to the real server, it replies as it normally would, and Mittelware swaps in your version before your app sees it. This page is about that one.

It's the most flexible action in Mittelware, and the one you'll use most.

Typical uses:

  • Mock an endpoint that doesn't exist yet: Mock an API before it exists.
  • Fake an error: a 500 with a JSON error body, to see the error screen.
  • Return unusual data: an empty list, a null where your code expects a string, a huge number.
  • Test a fix: edit the response by hand to check whether the bug is in the server's data or in your code, before you change either.
  • Add or remove a header, such as a cache header, or a CORS header if you want a specific value rather than what Mittelware sets by default.
  • Stream an answer in pieces, like an AI chat API: Stream a response.

Choose the behavior#

Choose Modify Response under Then…. The Behavior card at the top asks how the rule answers:

Behavior What happens
Instead of the server The request is answered here and the server is never asked. See Answer without the server
After the server responds The request is sent on to the server, and the response that comes back is changed on its way to your app

Each behavior keeps its own parts when you switch between them. Because a response condition needs a real response to look at, a rule with one can only use After the server responds.

The three parts#

Click Add action to pick which parts to change.

The Add action menu under Modify Response, offering Headers, Status Code and Body.
Change the headers, the status code, the body, or any combination.
Part What you can do
Status Code Replace the status, for example 200, 404 or 500. Pick it from a searchable list: type the number or part of its name
Headers Set a header (adding it, or replacing the existing value) or Remove it. You can add several rows
Body Replace the whole body. Typed in as Raw, loaded From file, or sent in pieces as a Stream

Every part is optional, and each can be added once. With After the server responds, anything you don't set passes through from the real response untouched. (With Instead of the server there is no real response, so set everything your app needs.) A rule that only sets a header leaves the status and the body exactly as the server sent them. To replace a response entirely, as a mock does, set the status, the headers and the body yourself. Each part is a card: its name in a title bar, then the value to apply. The bin button at the right end of the title bar removes the part, and the eye button beside it switches it off without deleting it (see Switch a part off).

Body#

The Body part has these modes:

Mode What it does
Raw The text you type into the editor, sent all at once. The editor highlights template variables and has an Expand button for long bodies
From file The contents of a file on your disk, read each time the rule runs. Handy for a large JSON document you'd rather keep in your editor. Text files can use template variables too; a binary file such as an image is sent as it is
Stream The text you give it, cut up and sent a piece at a time with pauses, like an AI chat answer. See Stream a response
Find and replace Only with After the server responds. Edits a few things inside the server's real page or script and leaves the rest as it was. See Find and replace in a response
From folder Only with Instead of the server. Answers from a whole folder of files on your computer. See Serve a folder

When a body is replaced, Mittelware corrects the response's Content-Length and removes any Content-Encoding, because your new body is plain and its size is known. A Content-Type isn't guessed for you: if the server's original was text/html and you replace the body with JSON, add a Headers part that sets Content-Type: application/json.

If a From file body can't be read, say because the file was moved after you saved the rule, that part is skipped and the real body goes through. Check Flows if a mock doesn't seem to apply.

Example: a complete fake response#

This is the rule from the walkthrough: whenever the app asks for one URL, ignore the server's answer and return a fake user. It uses Instead of the server, so the real server isn't even asked.

The complete form: app Microsoft Edge, label Docs: fake user, URL contains condition, Modify Response with a raw JSON body.
A whole rule on one screen.
  1. App: only Edge's traffic.
  2. Label: the name shown in the Rules list and in Flows.
  3. When…: the URL condition.
  4. Then…: Modify Response.
  5. The Body card, holding the replacement JSON.

Flows shows what happened. The badge at the top of the details panel names the rule that ran, and the Response tab shows the body your app actually received, not the one the server sent.

The Details panel with the badge Docs: fake user executed and the replaced JSON body.
1: the badge. 2: the response your app got.
  1. The badge: Docs: fake user executed.
  2. The body that replaced the server's answer.

Request conditions and response conditions#

A Modify Response rule works with both kinds of condition.

  • With request conditions only (a URL, a method…), the request goes to the real server, and the answer is changed on its way back.
  • With a response condition (a status code, a header or part of the body), the rule only runs once the real response has arrived and matches. That lets you change only the answers that look a certain way, for example make every 500 look like a 503.

In a response-based rule, the {{response.status}}, {{response.body}} and {{response.headers.Name}} template variables are available too, so you can build a new body out of the real one.

WARNING

With After the server responds, the real request reaches the server and only what comes back is changed. If that request creates an order or takes a payment, it still happens, and your app just won't know. For a request with side effects, answer Instead of the server or use Block Request, so it never leaves your computer.

Ideas#

To test… Set up…
The error screen Status Code 500, Headers Content-Type: application/json, Body { "error": "boom" }
An empty state Body { "items": [] }
A missing field Body with that field left out, or set to null
A slow response Any change at all, plus the rule's Delay (ms): Test timeouts and slow responses
A specific CORS header Headers → Set Access-Control-Allow-Origin to the value you want. Mittelware already makes responses readable by default, and your rule has the last word
Whether a bug is in the server or in your code Body edited to what the server should have sent: Why developers still need a network interceptor

Good to know#

  • A HEAD request has no body, so a Body part is ignored for it. Status Code and Headers parts still apply.
  • Everything unset is untouched, so you can also use this action to observe: set only a header such as X-Debug: true, and the rule's badge in Flows shows you which requests matched.
  • A browser may keep a saved copy of a page and not ask for it again, or accept a 304 Not Modified and ignore your replacement. If a rule matched (there's a shield) but nothing seems different, hard-reload with Ctrl + Shift + R. Rules explains why.
  • A rule changes a response only for the rule's App apps. Other applications are left alone.
  • A Modify Response rule that has no response condition answers every request it matches, so rules listed below it that look at the response never get a turn. It does work alongside a Modify Request rule, in either order: one changes what is sent, the other what comes back. See Order, and when two rules act on one request.