Let's assume a service offers some funcionality that I can use like this:
GET /service/function?param1=value1¶m2=value2
Is it right to say that I can use it with a POST query?
POST /service/function { param1 : value1, param2 : value2 }
Are these two queries the same? Can I use the second variant in any case or the documentation should explicitly say that I can use both GET and POST queries?
You can't use the API
using POST
or GET
if they are not build to call using these methods separetly. Like if your API say
/service/function?param1=value1¶m2=value2
is accessed by using GET
method. Then you can not call it using POST
method if it is not specified as POST
method by its creator. If you do that you may got 405 Method not allowed
status.
Generally in POST
method you need to send the content in body with specified format which is described in content-type
header for ex. application/json
for json data.
And after that the request body gets deserialized at server end. So you need to pass the serialized data from the client and it is decided by the service developer.
But in general terms GET
is used when server returns some data to the client and have not any impact on server whereas POST
is used to create some resource on server. So generally it should not be same.