javascript - Setting query string using Fetch GET request - Stack Overflow

PHOTO EMBED

Mon Aug 15 2022 05:06:52 GMT+0000 (Coordinated Universal Time)

Saved by @Fredysessie #javascript

// encode to scape spaces
const esc = encodeURIComponent;
const url = 'https://maps.googleapis.com/maps/api/geocode/json?';
const params = { 
    key: "asdkfñlaskdGE",
    address: "evergreen avenue",
    city: "New York"
};
// this line takes the params object and builds the query string
const query = Object.keys(params).map(k => `${esc(k)}=${esc(params[k])}`).join('&')
const res = await fetch(url+query);
const googleResponse = await res.json()
content_copyCOPY

https://stackoverflow.com/questions/35038857/setting-query-string-using-fetch-get-request