Is it a good practice to put many request parameters with GET request in REST API?
I have gone through couple of sites and tried to get the standard way of doing GET URI
with parameters implementation.
Here's what i am trying to achieve : search for all users having provided all the search criteria
.
Search criteria are like companyID
, sections
, offset
, limit
, orderby
, filter
.
As per basic standards GET
request can not have request body or payload
in it.
Will it be good way to make a GET
request and put all parameters behind ?
in the request URL, something like this :
GET http://localhost:8080/api/users?companyId=qwerty§ions=hr&offset=0&limit=20&oorderby=asc&filter=^[sSmM]
I was thinking to make a PUT
or POST
request and send all these data in payload, and implement the code to return the desired response, i.e list of users.
If i do this i am changing the default behavior of HTTP methods
.
Can you please guide me a way to get out of the situation. Thanks.
I think it does not matter how many parameters you put in a GET
request. The purpose of a POST
or PUT
request is not to keep your URL clean, but to aline with a REST structure.
the raw definition of GET, POST and PUT are
GET
: get a resource from your serverPOST
: create a resource on your serverPUT
: update a resource on your serverActually you can pass a request body with a GET request. It's just not very common to do it. Jquery supports this on the browser side and REST APIs such as for example the elastic search API use this. They have a nice json based query dsl and you can actually use a GET request for these. Because some HTTP frameworks don't support passing a body with a GET, Elasticsearch offers a fallback with POST as well.
As for using lots of url parameters, there are two issues you should keep in mind:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With