Gathering detailed insights and metrics for @mswjs/http-middleware
Gathering detailed insights and metrics for @mswjs/http-middleware
Gathering detailed insights and metrics for @mswjs/http-middleware
Gathering detailed insights and metrics for @mswjs/http-middleware
Spawn an HTTP server from your request handlers or apply them to an existing server using a middleware.
npm install @mswjs/http-middleware
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (95.43%)
JavaScript (4.57%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
120 Stars
61 Commits
12 Forks
4 Watchers
2 Branches
15 Contributors
Updated on Jun 11, 2025
Latest Version
0.10.3
Package Id
@mswjs/http-middleware@0.10.3
Unpacked Size
10.20 kB
Size
3.73 kB
File Count
8
NPM Version
10.8.2
Node Version
18.20.5
Published on
Jan 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
@mswjs/http-middleware
Spawn an Express server from your Mock Service Worker request handlers or apply them to an existing server using a middleware.
You should always prefer Mock Service Worker for API mocking because it can meet most of your requirements without having to spawn and maintain an actual HTTP server. Please refer to the Getting started tutorial to integrate next-generation API mocking into your application.
There are, however, use cases when this extension can be applicable:
curl
your mock definitions locally;1$ npm install @mswjs/http-middleware
1// src/mocks/handlers.js 2import { http, graphql, HttpResponse } from 'msw' 3 4export const handlers = [ 5 http.post('/user', () => { 6 return HttpResponse.json({ firstName: 'John' }) 7 }), 8 graphql.query('GetUser', () => { 9 return HttpResponse.json({ 10 data: { 11 user: { 12 firstName: 'John', 13 }, 14 }, 15 }) 16 }), 17]
Learn more about writing request handlers.
1import { createServer } from '@mswjs/http-middleware' 2import { handlers } from './handlers' 3 4const httpServer = createServer(...handlers) 5 6httpServer.listen(9090)
1import { createMiddleware } from '@mswjs/http-middleware' 2import app from './app' 3import { handlers } from './handlers' 4 5app.use(createMiddleware(...handlers))
createServer(...handlers: RequestHandler[])
Establishes a standalone Express server that uses the given request handlers to process all incoming requests.
1import { http, HttpResponse } from 'msw' 2import { createServer } from '@mswjs/http-middleware' 3 4const httpServer = createServer( 5 http.get('/user', () => { 6 return HttpResponse.json({ firstName: 'John' }) 7 }), 8) 9 10httpServer.listen(9090)
Making a GET http://localhost:9090/user
request returns the following response:
1200 OK 2Content-Type: application/json 3 4{ 5 "firstName": "John" 6}
createMiddleware(...handlers: RequestHandler[])
Creates an Express middleware function that uses the given request handlers to process all incoming requests.
1import { http, HttpResponse } from 'msw' 2import { createMiddleware } from '@mswjs/http-middleware' 3 4const app = express() 5 6app.use( 7 createMiddleware( 8 http.get('/user', () => { 9 return HttpResponse.json({ firstName: 'John' }) 10 }), 11 ), 12) 13 14app.use(9090)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
1 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
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
21 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