Gathering detailed insights and metrics for msw
Gathering detailed insights and metrics for msw
Gathering detailed insights and metrics for msw
Gathering detailed insights and metrics for msw
msw-storybook-addon
Mock API requests in Storybook with Mock Service Worker.
msw-auto-mock
Generate random mock data from OpenAPI descriptions for msw.
@kubb/plugin-msw
Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.
@orval/msw
[](https://badge.fury.io/js/orval) [](https://opensource.org/licenses/MIT) [
JavaScript (2.95%)
HTML (0.29%)
Shell (0.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
16,901 Stars
1,653 Commits
553 Forks
62 Watchers
25 Branches
167 Contributors
Updated on Jul 13, 2025
Latest Version
2.10.4
Package Id
msw@2.10.4
Unpacked Size
4.32 MB
Size
881.80 kB
File Count
559
NPM Version
10.8.2
Node Version
20.19.3
Published on
Jul 12, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
18
1
47
Industry standard API mocking for JavaScript.
"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."
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.
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.
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:
fetch
, axios
, react-query
, you-name-it;1// 1. Import the library. 2import { http, HttpResponse } from 'msw' 3import { setupWorker } from 'msw/browser' 4 5// 2. Describe network behavior with request handlers. 6const worker = setupWorker( 7 http.get('https://github.com/octocat', ({ request, params, cookies }) => { 8 return HttpResponse.json( 9 { 10 message: 'Mocked response', 11 }, 12 { 13 status: 202, 14 statusText: 'Mocked status', 15 }, 16 ) 17 }), 18) 19 20// 3. Start mocking by starting the Service Worker. 21await 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:
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.
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.
fetch
, axios
, etc. As a result, your tests know nothing about mocking;Here's an example of using Mock Service Worker while developing your Express server:
1import express from 'express' 2import { http, HttpResponse } from 'msw' 3import { setupServer } from 'msw/node' 4 5const app = express() 6const server = setupServer() 7 8app.get( 9 '/checkout/session', 10 server.boundary((req, res) => { 11 // Describe the network for this Express route. 12 server.use( 13 http.get( 14 'https://api.stripe.com/v1/checkout/sessions/:id', 15 ({ params }) => { 16 return HttpResponse.json({ 17 id: params.id, 18 mode: 'payment', 19 status: 'open', 20 }) 21 }, 22 ), 23 ) 24 25 // Continue with processing the checkout session. 26 handleSession(req, res) 27 }), 28)
This example showcases
server.boundary()
to scope request interception to a particular closure, which is extremely handy!
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!
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.
|
|
|
|
|
Become our silver sponsor and get your profile image and link featured right here.
Learn more on our GitHub Sponsors profile.
|
|
![]() |
Become our bronze sponsor and get your profile image and link featured in this section.
Learn more on our GitHub Sponsors profile.
|
![]() |
|
We've been extremely humbled to receive awards and mentions from the community for all the innovation and reach Mock Service Worker brings to the JavaScript ecosystem.
![]() |
Solution Worth PursuingTechnology Radar (2020–2021) |
![]() |
The Most Exciting Use of TechnologyOpen Source Awards (2020) |
No vulnerabilities found.
Reason
30 commit(s) and 23 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More