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 inreq.url.searchParams
using a much more comfortableURLSearchParams
interface.Note that
req.url
is aURL
instance, that is not serialized when printed into stdout. That's why you see{}
, which may falsely look like an empty object.