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.
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?
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