21 June 2007 - 0:29REST and WS - part 4 (or when REST turns ideological)
I was reading this post about writing complex applications REST-style and all seemed pretty well till I came across this business logic method wrapped up as a DELETE HTTP method:
| /{acct_id}/open_orders/{order_id} | DELETE | orders | delete | cancelOrder |
Mapping a CRUD method to a business method is a pretty bad thing, if anything the service which gets exposed REST-style should have very clear URL-to-business method mappings. It is pretty bad when you advertise one thing and when you do another. Using CRUD methods masquerading as business methods is pushing round pegs into square holes, if anything it obfuscates the contract that the REST-talking application has with the outside world.
Another bad thing with using CRUD methods for implementing business logic operations is that it seems that you run out of options due to the poverty of the REST syntax coming from the limited number of HTTP operations that it maps to. From what I see you can only do 4 methods on an order GET,POST,PUT and DELETE. What should I do if I want to partially commit my order (send my order to a another trader that will fulfill it)? DELETE is taken, it cancels an order, what other method in the HTTP protocol should I use REST-style in order to signal the server that I need to partially commit an order?
REST is pretty limited as far as I see it and I see it fit only for CRUD methods. You can tout all over the place that it scales to Internet-size but fact is 4 CRUD operations do not scale to complex interactions. You can do pretty much everything using those 4 operations by twisting your domain to fit your impoverished environment, but you can do the same thing in COBOL, Fortran, etc…
Later edit: You could have probably implement the cancel order method REST-style by creating a new URL on which you would cancel an order thru a PUT operation like below:
| /{acct_id}/cancel_orders/{order_id} | PUT | orders | create | cancelOrder |
But the problem still remains: you are trying to express a business contract using CRUD methods. Pushing round pegs into square holes…
Later edit: When you remote an application the contract that this application exposes should be crystal clear. Having CRUD operations masquerade as business logic operations obfuscates this contract.
No Comments | Tags: Development