neldelesndblogtagscontactresume
neldelesndblogtagscontactresume

2021 December 8thAccessing query parameters in MSWmsw 

Accessing query parameters in Mock Service Worker


Accessing query parameters in MSW

To access query parameters server-side, this SO answer suggests:

function get(req, res, next) { let param = req.query.foo ..... }

If using MSW however, the docs instructs to use req.url.searchParams. This is actually the recommended approach.

Hey, @Axnyff. Thanks for reporting this!

Please, can you try req.url.searchParams.get('email')?

The query parameters references via req.query were deprecated, as it effectively duplicates what you can access in req.url.searchParams using a much more comfortable URLSearchParams interface.

Note that req.url is a URL instance, that is not serialized when printed into stdout. That's why you see {}, which may falsely look like an empty object.

Footer


Related


References