Reputation: 4708
I am working on a Ticket Reservation application. I am required to build a web-service which takes in request for cancellation, checks with a downstream system (via SOAP), whether it can be cancelled, and returns the appropriate response to the calling system after updating my tables.
I have to build a bunch of similar web-services for cancellation, rescheduling, et for which I'm planning to use RESTful web-services
This I'm planning to achieve using the POST method of the REST API, using JAX-RS. I could see that all the web-services I'm going to build suit the POST verb, and the other HTTP methods (GET, POST and DELETE) doesn't seem like they need to be used here. In that case what is the actual use case of these HTTP methods in REST? Am I right in using only POST?
Upvotes: 0
Views: 13604
Reputation: 43087
Your REST resource is the ticket. Use GETs to read the ticket, PUT to modify the ticket state, and DELETE to do a logical delete (cancellation).
For any other operation, use the wildcard operation POST.
Have a look at this blog post Brief Introduction to REST, where the author goes through the core REST principles.
Upvotes: 3
Reputation: 4482
There's quite a lot to say about designing RESTful applications. You really should read one or more of these books: "Restful Web Services" - http://amzn.com/0596529260, "RESTful Web APIs" - http://amzn.com/B00F5BS966, "REST in Practice: Hypermedia and Systems Architecture" - http://amzn.com/B0046RERXY or "RESTful Web Services Cookbook" - http://amzn.com/B0043D2ESQ.
Get a cup of coffee and enjoy some reading :-)
Upvotes: 0
Reputation: 1600
Consider your Ticket Reservations as your application resources. Clients to your application would:
GET
request to retrieve a representation (XML, JSON or anything else) one or many ticket reservations (given the URL they use, eg: /tickets
to retrieve all of them - or all they are allowed to see, /tickets/1
to retrieve a representation of the Ticket Reservation whose id is 1
, tickets/?start=0&size=10
for paginated content, etc.)POST
requests on /tickets
to create a new reservation (and the response would provide the client with a location
giving the location of the created reservation)PUT
request to /tickets/1
(with a representation of the new reservation in the request body) to update the reservation identified by 1
DELETE
request to /tickets/1
to delete the reservation identified by 1
The main idea behind the use of such verbs is that the URLs should identify resources (and not actions), and the HTTP verb would be the action.
If you use everything with POST
, you'll be more or less doing SOAP.
This article will give you more information on hat I tried to hihlight above: http://martinfowler.com/articles/richardsonMaturityModel.html
Upvotes: 0
Reputation: 30310
For the purpose of a cancellation, I would actually use the DELETE method. In the case of a successful cancellation, return a 200 with either response body confirming success or a response body containing the details of the reservation. Or a 204 if you don't want to return a body.
If it can't be canceled, you have your choice from the 400 series of errors (e.g. 404 if there is no such reservation, 403 if the request is forbidden, etc.) or the 500 series if there is a bug or malfunction.
You will certainly use the other HTTP verbs for all the other reservation actions--making a reservation, changing it, etc.
Upvotes: 2