MK

HTTP Mock Builder

Define a mock HTTP endpoint and generate ready-to-use code for Express.js, MSW, or JSON Server.

Opens your print window: choose "Save as PDF". The file is named "HTTP Mock Builder - MondayTool".
About this tool

Last updated:

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

TabWhat you get
Express.jsAn app.get(...) style route that sets your headers and calls res.status(code).json(body). A delay wraps it in setTimeout.
MSWAn http.get(...) handler using HttpResponse.json with your status and headers. A delay adds await delay(ms).
JSON ServerA 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.

More to explore

Related Developer Tools

Browse all tools from the same category.

Showing 1-2 of 49