I am developing a RESTful web service in Java which on clients requests receives a request body which contains a set of computation tasks. The service(server) does the task and returns the output of the task to the client. I am having a problem on which HTTP method to use for the request - POST or PUT? I have read that POST is used for creating a resource and PUT is used for creating/updating a resource. But here I am doing neither an updating nor creating. But still I want my request body to contain the set of tasks for the server to do. So which HTTP method should I use?
Asked
Active
Viewed 1,059 times
3 Answers
2
if you want to create a new resourse on your server then you should to use POST method. Your task for server - is resourse which you'll create by request. So, use POST.

Maksim Grakov
- 91
- 6
-
but I am not creating any resource? Thats why I wanted to know which method to use. – Ramesh Singh Mar 21 '16 at 15:32
1
The way you invoke the REST service needs to accept a JSON. Suitable methods to send json as a part of body is POST and PUT, that are documented for create/update request.
Long answer short, use either POST or PUT which are suitable to post JSON and send back reply.

Nageswara Rao
- 954
- 1
- 10
- 32
-
-
The REST specifications are based on CRUD operation on a database table, parameter of json are parallels to columns. It doesn't limit us to write custom logic at the server side. Hence you can leverage POST/PUT which accepts json doc through body as input to your server side operation. Accepting json document as part of request is not possible in other request types like GET. – Nageswara Rao Mar 21 '16 at 16:46
0
Maybe this question Call a Server-side Method on a Resource in a RESTful Way could help to understand how to use server-side method calls with a rest api in addition to Maksim Grakov's answer