Hi i have a backend api which listen for /assets
with some query parameters
this kind of call always works
/assets?id=1&type=filter
/assets?type=filter&id=1
BUT this kind url throws 404
/assets&id=1?type=filter
/assets&type=filter?id=1
Question: how to make this kind of url /assets&type=filter?id=1
in correct format
CodePudding user response:
Query parameters take the form of a ?
followed by a set of key=value pairs separated by &
characters. The ?
and &
are not interchangeable.
Whatever method you are using to construct the URLs (which you haven't shown us but I assume involves mashing strings together): stop. Use the URL API instead.
const url = new URL('/assets', location);
url.searchParams.append('id', 1);
url.searchParams.append('type', 'filter');
console.log(url.toString());
CodePudding user response:
/assets&id=1?type=filter
/assets&type=filter?id=1
These are invalid url formats. To pass your query params you should at the end of url add ?
, and then use &
to add more query params