Middleware for Requests
See original GitHub issueIs your feature request related to a problem? Please describe. Middlewares would help in building dev tools/extend MSW without having to fork the repo.
Let’s say we want to “monitor” all the requests that are responded by the server. So that we can assert the requests made. Middleware/emitting responded event would help in building that.
Describe the solution you’d like Should be able to add “middleware” or event emitted.
server.middlewares(middleware)
Describe alternatives you’ve considered Right now to achieve this, we can add some logic to catch request in each handler.
let loginRequests = [];
server.use(
rest.post('/login', (req, res, ctx) => {
loginRequests.push(req);
return res(ctx.json({ data: 'data'}));
}),
);
But this would have to duplicated and we can’t reliably abstract this logic out.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (7 by maintainers)
Top Results From Across the Web
requests-middleware - PyPI
TL;DR: requests-middleware is a custom transport adapter that allows simple composition of HTTP interactions. The python-requests library makes excellent ...
Read more >ASP.NET Core Middleware | Microsoft Learn
Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component: ... Request delegates are used to ...
Read more >jmcarp/requests-middleware: Composable plugins ... - GitHub
TL;DR: requests-middleware is a custom transport adapter that allows simple composition of HTTP interactions. The python-requests library makes excellent ...
Read more >Writing middleware for use in Express apps
Middleware functions are functions that have access to the request object ( req ), the response object ( res ), and the next...
Read more >Conditional Middleware based on request in ASP.NET Core
The top-most piece of middleware in your application will always get called for each request. This is done automatically by the framework. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Secretmapper you can encapsulate this logic into a high-order resolver:
We can establish an event-based API that could also support request start/finish notifications (#388) for users to execute their logic.
You could then use this API in your tests to monitor all requests like so:
Would this work for your use case?