question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to Original Request on handlers.

See original GitHub issue

Hi. 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
otaciliolacerdacommented, Oct 1, 2020

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.

1reaction
otaciliolacerdacommented, Oct 2, 2020

Yes, this is what I am currently doing. 😀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found