msw is a free, open source frameworks & platforms project written in TypeScript and released under MIT. It has 18,210 GitHub stars, 626 forks and 37 open issues, and was last pushed 10 hours ago. On this registry it ranks #18 of 44 tracked projects in Frameworks & Platforms, with 5 head-to-head comparisons available.

What is msw?

Mock Service Worker (MSW) is an MIT-licensed TypeScript library that intercepts network requests at the Service Worker level so JavaScript applications and tests can run against mocked APIs without any change to application code, and it is built for front-end and full-stack JavaScript developers who need consistent API mocking in the browser, in tests, and during local development.

What it is

Mock Service Worker is a dedicated layer of request interception that lives in the JavaScript and TypeScript ecosystem. In the browser it uses the Service Worker API, which is normally used for caching, to respond to intercepted requests with mock definitions at the network level. Because the interception happens after requests have left the application, the application itself knows nothing about whether something is mocked or not. The project is published on GitHub under the mswjs organisation and carries the topics api, api-mocking, devtools, mock, mock-service-worker, mocking, mocking-framework, mocking-library, msw, mswjs, and service-worker. At the time of writing the repository has 18,210 stars, 626 forks, 37 open issues, and a last push of 2026-09-18.

The concrete problem it solves is request stubbing. Most API mocking libraries open up the application and remove the part that performs the request, replacing it with a black box; MSW leaves the application intact and 1-1 as it is in production, and lives in a separate box beside it. That means no stubbing of fetch, axios, react-query, or any other client, and no adapters or bloated configuration. The same mock definition can be reused for unit, integration, and E2E testing as well as local development and debugging, all running against one network description.

Key capabilities

  • Request interception at the network level through the Service Worker API, so the entirety of the application's code runs before a response is returned.
  • setupWorker API for in-browser usage, imported from msw/browser.
  • Request handlers described with http and HttpResponse, both imported from msw, as in http.get('https://github.com/octocat', ...).
  • Responses built with HttpResponse.json, including control over status codes, status text, headers, cookies, and delays.
  • Express-like routing syntax that matches requests using parameters, wildcards, and regular expressions.
  • Complete custom resolvers for cases where a static response is not enough.
  • One shared mock definition across unit, integration, and E2E tests plus local development, without adapters.

Who uses it and how

  • Front-end teams building in the browser against an API that does not exist yet, designing the API as they go rather than waiting for a backend.
  • Teams that already have an API and want to augment it with mocked responses for edge cases without touching production resources.
  • Test suites that need the same handlers to serve unit tests, integration tests, and end-to-end runs.
  • Projects mocking REST and GraphQL APIs, and WebSocket APIs, as covered by the Egghead courses the project has partnered on.
  • Developers who want mocked responses visible in browser DevTools, as described in the Kent C. Dodds quote, rather than hidden behind a stubbed client.

Getting started

Install the msw package, import http and HttpResponse from msw and setupWorker from msw/browser, describe network behavior with handlers, then start the Service Worker with await worker.start(). The project points to its official documentation, with a Quick Start at https://mswjs.io/docs/quick-start and the full docs at https://mswjs.io/docs.

How it compares

No list of comparable mocking products is provided in the facts, and no other API mocking tool is named for comparison, so MSW stands alone in this registry on that axis. What the facts do support is the difference in approach: most mocking libraries stub the request client, while MSW intercepts at the network level and leaves the application unchanged. It also offers a Discord server, a usage examples repository at https://github.com/mswjs/examples, and documentation and tutorials as the main support surfaces.

When to use it — and when not to

The README is deliberately brief and defers almost all setup detail to https://mswjs.io/docs, so a team that wants everything in one place will need to follow the external documentation rather than the repository alone. Because the headline capability depends on the Service Worker API, the in-browser story is the one the project leads with, and teams that cannot rely on that environment should verify their target usage in the docs before committing. It is also a mocking layer, not a backend: teams that need persistent, shared API fixtures across many consumers should look at a real server or a contract-testing tool instead.

project readme (upstream, from github) — read inline

Mock Service Worker

Industry standard API mocking for JavaScript.

Join our Discord server



Features

  • Seamless. A dedicated layer of requests interception at your disposal. Keep your application's code and tests unaware of whether something is mocked or not.
  • Deviation-free. Request the same production resources and test the actual behavior of your app. Augment an existing API, or design it as you go when there is none.
  • Familiar & Powerful. Use Express-like routing syntax to intercept requests. Use parameters, wildcards, and regular expressions to match requests, and respond with necessary status codes, headers, cookies, delays, or completely custom resolvers.

"I found MSW and was thrilled that not only could I still see the mocked responses in my DevTools, but that the mocks didn't have to be written in a Service Worker and could instead live alongside the rest of my app. This made it silly easy to adopt. The fact that I can use it for testing as well makes MSW a huge productivity booster."

Kent C. Dodds

Documentation

This README will give you a brief overview of the library, but there's no better place to start with Mock Service Worker than its official documentation.

Examples

Courses

We've partnered with Egghead to bring you quality paid materials to learn the best practices of API mocking on the web. Please give them a shot! The royalties earned from them help sustain the project's development. Thank you.

Browser

How does it work?

In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the Service Worker API, which can intercept requests for the purpose of caching, Mock Service Worker responds to intercepted requests with your mock definition on the network level. This way your application knows nothing about the mocking.

Take a look at this quick presentation on how Mock Service Worker functions in a browser:

What is Mock Service Worker?

How is it different?

  • This library intercepts requests on the network level, which means after they have been performed and "left" your application. As a result, the entirety of your code runs, giving you more confidence when mocking;
  • Imagine your application as a box. Every API mocking library out there opens your box and removes the part that does the request, placing a blackbox in its stead. Mock Service Worker leaves your box intact, 1-1 as it is in production. Instead, MSW lives in a separate box next to yours;
  • No more stubbing of fetch, axios, react-query, you-name-it;
  • You can reuse the same mock definition for the unit, integration, and E2E testing. Did we mention local development and debugging? Yep. All running against the same network description without the need for adapters or bloated configurations.

Usage example

// 1. Import the library.
import { http, HttpResponse } from 'msw'
import { setupWorker } from 'msw/browser'

// 2. Describe network behavior with request handlers.
const worker = setupWorker(
  http.get('https://github.com/octocat', ({ request, params, cookies }) => {
    return HttpResponse.json(
      {
        message: 'Mocked response',
      },
      {
        status: 202,
        statusText: 'Mocked status',
      },
    )
  }),
)

// 3. Start mocking by starting the Service Worker.
await worker.start()

Performing a GET https://github.com/octocat request in your application will result into a mocked response that you can inspect in your browser's "Network" tab:

Chrome DevTools Network screenshot with the request mocked

Tip: Did you know that although Service Worker runs in a separate thread, your request handlers execute entirely on the client? This way you can use the same languages, like TypeScript, third-party libraries, and internal logic to create the mocks you need.

Node.js

How does it work?

There's no such thing as Service Workers in Node.js. Instead, MSW implements a low-level interception algorithm that can utilize the very same request handlers you have for the browser. This blends the boundary between environments, allowing you to focus on your network behaviors.

How is it different?

  • Does not stub fetch, axios, etc. As a result, your tests know nothing about mocking;
  • You can reuse the same request handlers for local development and debugging, as well as for testing. Truly a single source of truth for your network behavior across all environments and all tools.

Usage example

Here's an example of using Mock Service Worker while developing your Express server:

import express from 'express'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

const app = express()
const server = setupServer()

app.get(
  '/checkout/session',
  server.boundary((req, res) => {
    // Describe the network for this Express route.
    server.use(
      http.get(
        'https://api.stripe.com/v1/checkout/sessions/:id',
        ({ params }) => {
          return HttpResponse.json({
            id: params.id,
            mode: 'payment',
            status: 'open',
          })
        },
      ),
    )

    // Continue with processing the checkout session.
    handleSession(req, res)
  }),
)

This example showcases server.boundary() to scope request interception to a particular closure, which is extremely handy!

Sponsors

Mock Service Worker is trusted by hundreds of thousands of engineers around the globe. It's used by companies like Google, Microsoft, Spotify, Amazon, Netflix, and countless others. Despite that, it remains a hobby project maintained in a spare time and has no opportunity to financially support even a single full-time contributor.

You can change that! Consider sponsoring the effort behind one of the most innovative approaches around API mocking. Raise a topic of open source sponsorships with your boss and colleagues. Let's build sustainable open source together!

Golden sponsors

Become our golden sponsor and get featured right here, enjoying other perks like issue prioritization and a personal consulting session with us.

Learn more on our GitHub Sponsors profile.


Silver sponsors

Become our silver sponsor and get your profile image and link featured right here.

**Learn more on our [

readme truncated — read the full docs on github

Frequently asked questions

Is msw free to use?

msw is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does msw do?

Industry standard API mocking for JavaScript.

What is msw written in?

msw is primarily written in TypeScript. Its source is publicly available at https://github.com/mswjs/msw, and it has 18,210 GitHub stars.