skeith22's avatar

Pass parameters to GET request in fetch API

does anyone know how to pass parameters in a GET request using fetch()?

p.s. I can't use Axios inside the web worker.

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

Use a query string

If you like the idea of a params object, then you can construct the URL using a URLSearchParams object:

let url = new URL('https://sl.se')
url.search = new URLSearchParams({
    lat:35.696233,
    long:139.570431
})

fetch(url)
1 like
skeith22's avatar

I was actually looking for a way to convert Object to query string parameters.

Please or to participate in this conversation.