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
npm install @mswjs/http-middleware
Typescript
Module System
Min. Node Version
Node Version
NPM Version
69.5
Supply Chain
89.7
Quality
81.8
Maintenance
100
Vulnerability
99.3
License
TypeScript (95.43%)
JavaScript (4.57%)
Total Downloads
1,941,128
Last Day
4,536
Last Week
22,581
Last Month
114,001
Last Year
1,131,802
115 Stars
60 Commits
13 Forks
4 Watching
1 Branches
15 Contributors
Minified
Minified + Gzipped
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
Publised On
12 Jan 2025
Cumulative downloads
Total Downloads
Last day
-18.1%
4,536
Compared to previous day
Last week
-26.2%
22,581
Compared to previous week
Last month
-3.4%
114,001
Compared to previous month
Last year
111.8%
1,131,802
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 dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
2 commit(s) and 1 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
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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