0

I am asking about what the accepted best practices are in retrieving information from a REST server where the client needs to provide some data.

Usually it is done as CGI parameters... but is it OK to do a POST with a json payload with the info in order to get information?

steve landiss
  • 1,833
  • 3
  • 19
  • 30
  • Could you provide an example for such a request? What would the parameters be like? –  Mar 19 '15 at 07:39

1 Answers1

0

Yes.

Although typically you use a GET to retrieve data in RESTFul services it is not actually specified that it has to be that way. It is quite acceptable for it do be done by a POST.

See related question PUT vs POST in REST

For it to be RESTful it has to have the following. Uniform Interface, Stateless, Cacheable, Client-Server, Layered System, Code on Demand (optional). There is no specification anywhere that says you must use a particular HTTP method for a particular function or even HTTP methods at all.

Community
  • 1
  • 1
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
  • I disagree. To get a resource, `GET` is to be used. –  Mar 19 '15 at 07:34
  • Have you got any facts to back up your disagreement? – Dijkgraaf Mar 19 '15 at 19:25
  • "or even HTTP methods at all" That is true. It is also true that, as long as your protocol allows it, you can make a HTTP `DELETE` request with JSON body which the server uses to create a new resource. But doing REST this way would not be what most people expect. Since the OP is asking about HTTP `POST` for making a request that basically has `GET` semantics, it is bad advise to tell him: "You can do whatever the proctol dos not reject since REST is only an architectural style that follows a set of principles." Doing REST in the real world also means: Don't confuse people. You do. –  Mar 19 '15 at 20:01