• Post Reply Bookmark Topic Watch Topic
  • New Topic

RESTful web services: what are they well addressed for ?  RSS feed

 
Claude Moore
Ranch Hand
Posts: 875
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there guys,

while reading about RESTful web services, I've always been doubtful about how I should use them. Ok, as far as I understood, and very basically speaking, with REST services one has to deal with resources, identified with URI, and can manipulate those resources relying upon a "mapping" between HTTP protocol operations (or verbs) and operation run against those entities.

That's all fine, at least until we're dealing with listing data, executing CRUD operations and moreover, but I'm in doubt if REST may be applied when we're facing more complex business concepts. For example, how would you map a service request like "confirm costumer order, and, if stock quantity falls below a certain soil, execute a purchase request to each item's preferred supplier ?"

I think that a similar scenario would be better developed with old-fashoned JAX-WS services than with REST approach.. For example I would have to issue:

- a PUT to update customer order status
- a GET to retrieve out-of-stock goods
- a PUT for suppliers orders.

And all of these operations must be expressed with proper URI.

What do you think about ?

Thank for your help.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sequence of operations is business logic and should be handled centrally by server along with data validation, persistence and transactional constraints. It should never be handled by any client.

A REST URL can be

 
Claude Moore
Ranch Hand
Posts: 875
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply, Karthik.

PUT http://..../stockservice/purchaseorder/{customerId}/ => "Create a new purchase order"


So, in a REST approach, can you identify actions (in your example: purchaseorder), not only entities with an URI ?

Apart my very bad example (indeed, it was totally wrong, sorry for that), my confusion arise mainly just becasue I've read that with REST you have to deal
with entities, not with actions, and you have to map CRUD operations with HTTP Protocol verbs.
In this way, when you issue a POST command you're actually doing an INSERT of an entity in your system, with a DELETE you're going to delete an entity and so on.


Now with an URI like stockservice/purchaseorder/, it seems to me you're mixing entities with processing involving those entities... PUT, DELETE, POST are still maintaining
a distinct meaning ?

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my example, I meant "purchase order" itself is an entity, as opposed to another kind of order like say "sale order". I didn't mean it as "purchase"[=action/verb] an "order"[=entity].
But I can see how that can be easily be misunderstood. With "purchase order" as entity, PUT/POST/DELETE still hold true; as in "update this purchase order" or "delete this purchase order".

It could also be modelled as:


Note that the action (what to do on this order) has been shifted to the body of the request.

If the service does something that is not simple CRUD,
- either give more information about the action in body of a request or as a request parameter.
- or turn the action into a noun and make it part of the URL (like "/ordervalidation/{order_id}").

It's a matter of choosing a URL based on maintainability and readability. In some cases, a broad URL like /order/ which covers any kind of order may be more appropriate; in other cases, a narrower URL like /purchaseorder/ or /saleorder/ may be more appropriate.
 
Claude Moore
Ranch Hand
Posts: 875
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, so explained it's ver much clear er for me... thanks a lot !! just another question: after transforming an action (validate an order) in an entity (ordervalidation), has still sense maintain a distiction with get,post,put, or delete http verbs? It doesn't seems the case to me, but i'd love to have your opinion.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A client that sees a URL like "/ordervalidation" will not be expecting it to modify the entity in any way. I feel that a good RESTful service should name its URLs carefully and not do anything that will surprise its clients.
So PUT, POST, DELETE can be treated as unsupported operations and return appropriate HTTP error codes like 405 (method not supported) or 403 (forbidden).
GET is still valid and will be the only supported verb in this example.
 
Claude Moore
Ranch Hand
Posts: 875
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your vision about RESTful seems very neat to me.
Thank you man, you really clarified my ideas about REST !!!
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome! Glad it helped.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!