iberbeu iberbeu - 3 months ago 20
reST (reStructuredText) Question

REST service without sending object, GET, POST or PUT?

I have a REST service, which creates some elements in my database. These elements are created "statically" in the server method and are not given by the client, but will be then returned to the client after the operation is complete.

If I declare the service as PUT/POST (because I want to create new things) the client is required to send an object, which has to be null because the client has no object to send (everything is done in the server).

If I declare it as GET I won't need to send a null-object, but my GET-method will be creating things, which I don't expect from a GET-method

So, what will be the best approach to follow in such a case: PUT, POST or GET?

Answer

Here is the way I was expecting this to be done.

  1. Use ServletContextListener and on context initialized you invoke your logic. Refer this link
  2. And for the user expose a url http://yoururl/get/created/stuff and return the elements which you have created earlier. May be pull from db and convert into json/xml/plain-text etc.

Some more references