I faced a question today.
I have an API made with Node JS, but in certains endpoints, I need to receive some params with spaces.
These endpoints are GET, but my question is, is that a good practice use form-url-encoded body in GET endpoints?
What must be the best way to pass parameters with spaces to a GET endpoint?
You should not use request bodies with GET
. Request bodies are/should be ignored and many libraries drop them.
The purpose of GET
is to get the representation of a resource at the specified URI, nothing else. All the information about the resource you want to receive the state of should be in the URI. You can encode spaces in URIs though, just use a url-encoding library.
If you are talking about 'parameters', this sounds more like a RPC call to me, and POST
might be more appropriate for that. POST
does allow request bodies and URL encoded or JSON bodies are fine for that.