Reputation: 21320
I need to expose a rest api which needs 4 parameters, as of now. I have two options:
1) GET request with 4 query params
2) POST request with an Object passed that encapsulates 4 parameters.
If i use case 1)
, then what if in future, more parameters need to be sent thereby making URL lengthy as query parameters will be increased. If i use case 2)
, then rest guideline will be violated as POST only meant to create/update.
Please let me know what is best approach in this case.
Upvotes: 8
Views: 6361
Reputation: 379
Filtering params can also be sent as header params in a get request as well.
Besides if necessary sending more request params doesn't harm.
Upvotes: -1
Reputation: 438
If you need to pass long parameters, or binary ones, you'd normally use HTTP POST requests, and include the parameters in the POST body.
As a rule, GET requests should be for read-only queries; they should not change the state of the server and its data. For creation, updating, and deleting data, use POST requests. (POST can also be used for read-only queries when complex parameters are required.)
Reference: http://rest.elkstein.org/2008/02/more-complex-rest-requests.html
Also, you can refer here: What is the best way to design a HTTP request when somewhat complex parameters are needed?
Upvotes: 5