MSW Handler Builder
none
none
handlers.ts (MSW v2)
import { http, graphql, HttpResponse } from "msw";
export const handlers = [
// List users
http.get("/api/users", async ({ request }) => {
return HttpResponse.json([{"id":1,"name":"Ada"}], { status: 200, headers: { "Content-Type": "application/json" } });
}),
// GraphQL user query
graphql.query("GetUser", async () => {
return HttpResponse.json({ data: {"user":{"id":"1","name":"Ada"}} }, { status: 200 });
})
];
What This Tool Does
MSW Handler Builder is built for deterministic developer and agent workflows.
Visually compose Mock Service Worker REST and GraphQL handlers with method, path, query, header matchers, response shapes, status codes, delays, and one-shot or persistent semantics. Exports an MSW v2 handlers.ts file.
Use How to Use for execution steps and FAQ for constraints, policies, and edge cases.
Last updated:
This tool is provided as-is for convenience. Output should be verified before use in any production or critical context.
Agent Invocation
Best Path For Builders
Browser workflow
Runs instantly in the browser with private local processing and copy/export-ready output.
Browser Workflow
This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.
/mock-service-worker-handler-builder/
For automation planning, fetch the canonical contract at /api/tool/mock-service-worker-handler-builder.json.
How to Use MSW Handler Builder
- 1
Add a handler
Use the REST or GraphQL button to drop a starter handler into the list. Each handler has its own editor pane that you reach by clicking it in the sidebar.
- 2
Configure matchers
For REST, set method, path, query parameters, and required headers. For GraphQL, pick query or mutation and enter the operation name MSW will match on.
- 3
Shape the response
Pick a status code, choose JSON or text, edit the response body and headers, optionally add a delay, and decide between persistent and one-shot semantics.
- 4
Copy or download handlers.ts
The generated MSW v2 module updates on every change. Use Copy for clipboard or Download to save handlers.ts straight into your project's mocks directory.