# HTTP Mock Builder

> Define a mock API endpoint with method, path, status, headers, JSON body and delay, then copy ready-made Express.js, MSW or JSON Server code.

- Page: https://mondaytool.com/tools/http-mock-builder
- Category: developer-tools
- Price: free, no sign-up. Most tools run in the browser, so input is not uploaded.
- Use it: open https://mondaytool.com/tools/http-mock-builder. It is an interactive web page; this file is its documentation.

Last updated: 14 October 2026

## Generate mock API code in seconds

This **HTTP mock builder** turns one endpoint definition into ready-to-paste mock code for Express.js, Mock Service Worker (MSW) or JSON Server. You pick the method, path, status code, headers, JSON body and an optional delay, and the tool writes the route for you. It is handy when the real backend is not ready yet, or when you need a predictable response for tests and demos. The tool only generates code. It does not host a mock server, so you run the code in your own project.

## How to use it

1. Choose a method: **GET**, **POST**, **PUT**, **PATCH** or **DELETE**.
2. Enter the path, such as `/api/users/:id`, the status code and a delay in milliseconds (0 for none).
3. Edit the response headers. `Content-Type: application/json` is added by default. Use **+ Add header** or the ✕ button to change the list.
4. Type the response body as JSON. Click **Format JSON** to tidy it and catch syntax errors.
5. Click **Generate Code**, pick a tab, then click **Copy**.

## How it works

| Tab | What you get |
| --- | --- |
| Express.js | An `app.get(...)` style route that sets your headers and calls `res.status(code).json(body)`. A delay wraps it in `setTimeout`. |
| MSW | An `http.get(...)` handler using `HttpResponse.json` with your status and headers. A delay adds `await delay(ms)`. |
| JSON Server | A `db.json` file plus a start command. Method, status, headers and delay are not used here. |

For JSON Server, the resource name comes from the first part of the path. A JSON array is used as is. A single object is wrapped in an array and given `id: 1` unless it already has an id. Everything runs in your browser. Nothing is sent to a server.

## Tips

- The output updates when you click **Generate Code** or switch tabs. Click again after you change the form.
- If the body is not valid JSON, the Express and MSW code fall back to `{}`. Use Format JSON first.
- For JSON Server, use a short path like `/users`. With `/api/users/:id` the resource would be named `api`.
- The Express code is a single route. Paste it into an app where `app` is already created. Add the MSW handler to your handlers list.

## Frequently asked questions

### Does this tool host a live mock API?

No. It writes code you can paste into your own Express app, MSW setup or JSON Server folder. You run that code locally or in your test environment.

### Which MSW version does the code target?

The handler imports `http` and `HttpResponse` from `msw`, which is the API used by MSW 2.x. Older 1.x projects use `rest` and `ctx` instead.

### Can I simulate a slow or failing endpoint?

Yes. Set a delay in milliseconds to slow the response, and set a status code such as 404 or 500 to test error handling in your app.
