3 ms·
You've made everything non-destructive in your example, which I think makes REST a better fit - although even then, note how your example requests are almost al
by lmm 12y ago
You've made everything non-destructive in your example, which I think makes REST a better fit - although even then, note how your example requests are almost all GET or POST.
> does not conform to REST best practices because POST is for creating new records -- immediately the developer is confused
You've got it backwards. The developer doesn't start with that request and try to figure out what it does. The developer starts by wanting to e.g. convert an image to gif, and trying to figure out what call will let them do that.
POST /image/ <response from /image/1/jpeg> -> 200 OK, { id: 2 }
PUT /image/2 <response from /image/1/png> -> 200 OK
Notice how you're offering the same operation through two different verbs here - exactly what the article is advocating!
The specific domain where I've seen REST go most wrong is contracts for large scale commercial insurance / reinsurance. Operations are things like:
* Split a contract into multiple loss layers (0-25%, 25%-50% etc.)
* Reshuffle the contract hierarchy - e.g. change a ship insurance contract from being split into hull / cargo and then individually layered in them, to being split into layers and then each of those split hull / cargo
* Compare two quotes, potentially made against different versions of the contract
All these are things you can encode as REST operations - you can think of particular things to be entities and declare each of these to be creating or deleting entities. But that's in the same sense that you can encode any data as binary. What we found was that users - people with actual domain knowledge - didn't think in terms of those entities. They thought in terms of these operations, which had their own names that everyone in the industry understood, and the only entity they thought of was the single "current version of the contract" - everything else was one of several different kinds of "change the contract" operation. So the only mapping that made sense to a client familiar with the domain was a bunch of different POST operations on a contract object.