Access to Original Request on handlers.
See original GitHub issueHi. Thanks for this awesome tool. It is making my life easier. 😀
Is your feature request related to a problem? Please describe.
Given the request handler below:
rest.post('/path', (req, res, ctx) => {
// ...
}),
The req
object is slightly different in the Browser and Node environments.
In Node:
- If the content-type is json it parses it and makes the data available on
req.body
. - Otherwise it pass the original Body from the request. With this we have the chance to receive other object responses like FormData.
In the Browser:
- msw parses the body as text before pass it to the handler.
Describe the solution you’d like
Have a clone of the original request in the req
object. This way the handler has access to the Body mixin methods to read the data in other formats: FormData, Blob, ArrayBuffer, etc.
Describe alternatives you’ve considered
To mock a multipart/form-data
request I had to create a custom parser. It works just fine but if we have this feature available for free I guess it makes sense to passed it to the handler.
Does this makes sense? I can submit a PR with the suggested changes.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Can access original request object in handlers #491 - GitHub
I'm trying to add functionality add trace headers to logs and I want this trace header to be available everywhere.
Read more >How to get access to access request body inside Exception ...
You can create a request scoperd entity to keep requst body, @Component @RequestScope public class RequestDetails { private ...
Read more >How to write a request handler for users accessing a ...
You can use a request handler to build the same function as “url/file?guid” but without the need for a user to be authenticated....
Read more >Using a Request Object Event Listener - AWS Documentation
Request object is called, the event handler executes when the service object ... If you use response data inside a callback for the...
Read more >ExpressJS Series: What I need to know about the req Request ...
There are a lot things you can access in the route handler from the request object. It mainly takes care of the keeping...
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
Hi @marcosvega91 and @kettanaito,
First, thanks for the very fast response. I was not completely aware of the MessageChannel (I just read the WebWorker docs). Now knowing that it was not an easy win like I initially thought, I agree with @kettanaito. Maybe this is a customization to my use case: I am saving some data in-memory to simulate the interactions when running on the browser for fast prototyping.
Yes, this is what I am currently doing. 😀