Reputation: 121
I am currently using a @POST web service to retrieve data. My idea, at the beginning, was to pass a map of parameters. Then my function, on the server side, would take care of reading the needed parameters in the map and return the response. This is to prevent having a big number of function almost identical on the server side.
But if I understood correctly, @POST should be use for creation of content.
So my question: Is it a big programming mistake to use @POST for data retrieval? Is it better to create 1 web service per use case, even if it is a lot?
Thanks. Romain.
Upvotes: 4
Views: 2208
Reputation: 96434
POST is used to say that you are submitting data. GET requests can be bookmarked, POST can't. Before there were single page web appliations we used post-redirect-get to accepta data submission and display a bookmakable page.
If you use POST to retrieve data then web-caching doesn't work, because the caching code doesn't cache POSTS, it expects POST to mean it needs to invalidate its cache. If you split your services out use-case-wise and use GET then you can have something like Squid cache the responses.
You may not need to implement caching right now, but it would be good to keep the option open. Making your services act in a compliant way means you can get leverage from existing tools and infrastructure (which is a selling point of REST).
Upvotes: 6
Reputation: 122006
doGet();
Called by the server (via the service method) to allow a servlet to handle a GET request.
doPost()
Called by the server (via the service method) to allow a servlet to handle a POST request.
No issues with them.Both will handle your request.
Upvotes: -3