REst GET Vs POST with large message text

I have a situation where I am struggling with the REst GET and POST philosophy in the real world.

I have a REst call that is idempotent in nature. This requires a complex payload datatype in it (insurance policy in XML), makes complex business logic, and returns a premium. It does nothing in the state and therefore is essentially idempotent.

The REST call is currently POST. The valid excuse for this is that the body of the message is large and is likely to be lost and confused with an internet explorer. However, it is also idempotent and violates GET Vs POST completely.

Has anyone encountered this riddle before? Thank.

+3


source to share


3 answers


I have the same problem and my solution is pragmatic. My API uses POST even for idempotent when it encounters the limitations of a GET request, so:

If the form data would contain non-ASCII characters or;
If the form data set is large.

      



I think there are other exceptions, but I can't think of that right now.

UPDATE: One more exception, if for some reason I don't want the parameter to be visible in the request url, I also use POST to idempotent.

+1


source


I'm not sure if the implication is reversible:

GET SHOULD be idempotent

is what is defined, but nothing prohibits POST

being idempotent.



If I were you, I would go for the method POST

. Also, if your request contains an object, it cannot beGET

+2


source


While I don't think there is a good alternative to using POST requests for large GET components, you should keep in mind that POST requests are usually not cached by (reverse) proxies. Most HTTP caches (as I know) do not consider the POST body to compute the object cache. This can be a problem if your calculations are resource intensive.

0


source







All Articles