With the angular HTTP client, you actually don't need to construct the URL yourselves (and if you did, I would suggest you use the URLSearchParameters
API, again, not doing it yourself, but since you're using angular, forget about that lol). As explained here, you can simply pass the params
in the options
, and it will construct the query for you.
In your case, that would be:
return this.http.get<Item[]>(
`${this.apiUrl}/api/`,
{ params: { query: filterQuery }},
);
Also, no query=%22status:2%20OR%20status:3%22
is correct, as it results in the correct string when you run it through decodeURIComponent
:
console.log(decodeURIComponent("query=%22status:2%20OR%20status:3%22"));
I would first suggest you try to remove the extra /
at the end of your path (I'm currently not up to speed if the specifications allow that or not, but it seems uncommon).
"/api/?query="status:2 OR status:3"
^
| This here
According to: https://www.rfc-editor.org/rfc/rfc3986#section-6.2.3
Normalization should not remove delimiters when their associated component is empty unless licensed to do so by the scheme specification. For example, the URI "http://example.com/?" cannot be assumed to be equivalent to any of the examples above.
If MY interpretation of this is correct, the trailing slash will (potentially) result in an empty entry in the path component, which (potentially) causes different behavior.
And if that doesn't work, you should probably tell the "third party", that their API is not working .
If you want to further debug it, I would suggest copying the URL, that is not working, from the "Network" tab of your browser's debugging tools. Then put that into
fetch(<your url here>)
.then(r => r.json())
// or .then(r => r.text()) depending on what data is expected
.then(console.log);
and modify the URL until it works. If that works, you can adjust your angular code, so it gives you the matching output.