FREEDOM251

Freedom251 › API Mocking Tools

Mock Service Worker

Free plan Self-hostedWeb

Visit Mock Service Worker Alternatives

Mock Service Worker's own site

What Mock Service Worker is

Mock Service Worker (MSW) is a free, open-source API mocking library for browser and Node.js applications. It intercepts outgoing requests so developers can observe them and provide mocked responses, using the Fetch API to handle intercepted traffic. The project supports HTTP and REST, GraphQL queries and mutations, Server-Sent Events, and WebSocket APIs. Shared mock handlers can be reused across frameworks, tools and environments, including development, integration and end-to-end testing, Storybook and live demos. MSW works with native fetch and clients such as Axios, React Query and Apollo. In browsers, it registers a Service Worker for network-level interception, and the application must serve the worker script. In Node.js, setupServer enables API mocking in an application process or test runner. The project provides integration guides for Cloudflare, React Native, Storybook, Vite and Vitest, among others. Browser and Node.js interception have stated limits: Firefox does not notify the worker about page XMLHttpRequest requests, and Node.js requests made directly through net.connect() or net.createConnection() cannot be intercepted. Official Egghead courses require a paid subscription.

Who it suits

MSW suits developers who need reusable mocked API responses in browser or Node.js work, including development, tests, Storybook or live demos. It is also relevant to teams using the named request clients and integrations.

What it does well

  • Free and open source.
  • Mocks HTTP, GraphQL, SSE and WebSocket APIs.
  • Mock handlers can be reused across environments.
  • Works with native fetch, Axios, React Query and Apollo.

What to know first

  • Browser use requires serving a Service Worker script.
  • Firefox page XMLHttpRequest requests are not reported to the worker.
  • Direct net.connect() and net.createConnection() requests cannot be intercepted.
  • Official Egghead courses require a paid subscription.

Limits

Browser interception follows Service Worker constraints, including Firefox's handling of page XMLHttpRequest requests. Node.js interception does not cover requests made directly through net.connect() or net.createConnection(); GraphQL subscriptions are described as future support.

Getting started

  1. Open the MSW website and choose browser or Node.js integration
  2. For browser use, register the Service Worker and serve its worker script from the application
  3. For Node.js use, configure setupServer in the application process or test runner
  4. Define handlers for the HTTP, GraphQL, SSE, or WebSocket traffic you want to mock
  5. Reuse the client-agnostic handlers across your development, testing, Storybook, or demo environments

Verdict

MSW offers reusable request mocking across browser and Node.js contexts, with support for several API protocols and clients. Its interception approach has browser and Node.js boundaries, so check those limits against the requests your application makes.

Questions

How much does MSW cost?

MSW is free and has a free plan. There is no free trial because the project is offered as free software.

Which platforms does MSW support?

It supports self-hosted browser and Node.js use. Documentation also covers Cloudflare, React Native, Storybook, Vite, and Vitest.

Is MSW open source?

Yes. The project describes MSW as open-source and free to try.

Which API styles can it mock?

MSW supports HTTP and REST, GraphQL queries and mutations, Server-Sent Events, and WebSocket APIs.

Can existing request clients use MSW?

Yes. It works with native fetch and named clients including Axios, React Query, and Apollo.

Where can users get help?

The project points users to its debugging runbook, Discord, and GitHub discussions.

Facts from Mock Service Worker's own pages

Additional integrations
The MSW organization lists extensions for Playwright, Storybook, Cloudflare workerd, and SvelteKit. · github.com, 30 Sept 2026
Browser integration
In browsers, MSW uses the Service Worker API to intercept requests at the network level. · mswjs.io, 30 Sept 2026
Browser limitation
Because browser interception relies on the Service Worker API, browser-specific limitations apply; the docs also state that Firefox does not notify the worker about page XMLHttpRequest requests. · mswjs.io, 30 Sept 2026
Client compatibility
The documentation names native fetch and third-party clients including Axios, React Query, and Apollo as supported request clients. · mswjs.io, 30 Sept 2026
Learning resources
The documentation says its official Egghead courses require a paid subscription and help support the project. · mswjs.io, 30 Sept 2026
Limitations
MSW's GraphQL documentation says it supports queries and mutations, while subscriptions are described as coming in the future. · mswjs.io, 30 Sept 2026
Network APIs
MSW supports mocking REST, GraphQL, Server-Sent Events, and WebSocket APIs. · mswjs.io, 30 Sept 2026
Network standards
MSW uses the Fetch API to handle intercepted requests and construct mocked responses, including requests made with other clients. · mswjs.io, 30 Sept 2026
Node integration
In Node.js, MSW intercepts raw socket connections before they reach the network code written in C. · mswjs.io, 30 Sept 2026
Node.js integration
In Node.js, MSW provides setupServer for enabling API mocking in an application process or test runner. · mswjs.io, 30 Sept 2026
Node.js limitation
MSW cannot intercept requests made directly through net.connect() or net.createConnection(), which some libraries use. · mswjs.io, 30 Sept 2026
Open source
The project describes MSW as open-source and free to try. · mswjs.io, 30 Sept 2026
Paid learning
The documentation says its official Egghead courses require a paid subscription. · mswjs.io, 30 Sept 2026
Protocols
MSW supports mocking HTTP, GraphQL, Server-Sent Events, and WebSocket APIs. · mswjs.io, 30 Sept 2026
Purpose
Mock Service Worker (MSW) is an API mocking library for browser and Node.js that intercepts outgoing requests so developers can observe and respond with mocked responses. · mswjs.io, 30 Sept 2026
Request clients
MSW works with native fetch and third-party clients such as Axios, React Query, and Apollo. · mswjs.io, 30 Sept 2026
Reusable mocks
The same mock handlers can be reused for development, integration and end-to-end testing, Storybook, and live demos. · mswjs.io, 30 Sept 2026
Shared mocks
The same client-agnostic mocks can be reused across frameworks, tools, and environments, including development, integration and end-to-end testing, Storybook, and live demos. · mswjs.io, 30 Sept 2026
Support
The quick start directs users to a debugging runbook, MSW Discord, and GitHub Discussions for help. · mswjs.io, 30 Sept 2026
Tool integrations
The site provides integration guides for Cloudflare, React Native, Storybook, Vite, and Vitest, as well as browser and Node.js. · mswjs.io, 30 Sept 2026
What it does
MSW is an API mocking library for browser and Node.js that intercepts outgoing requests so they can be observed and answered with mocked responses. · mswjs.io, 30 Sept 2026

Where Mock Service Worker stands on Freedom251

Look at these too