Earlier quoted context omitted.
This is my approach as well. Works very well with an event-sourcing model. It is much easier to capture user intent with POST /api/customer/1/change-address-due-to-move { "address_1": "...", "address_2": "...", ... } than with: PUT /api/customer/1 { "address_1": "...", "address_2": "...", ... } Also, GET /api/resource/action is nice place for a payload describing the expected inputs to the action. Link it all togethe…
How about POST /api/customer/1/address {"address": "..."}
Do you really know why you prefer REST over RPC?
31–40 of 124 posts
Re: Do you really know why you prefer REST over RPC?
#32If you look at frameworks like Backbone, you can basically create models/collections for a simple CRUD app just by adding some values to a declarative hash (URI, primary key, etc.). Because everything is so predictable, it's really easy to specify a default behavior.
Granted, you could certainly do something similar with an RPC API, but I still think it would likely be harder to generalize.
Re: Do you really know why you prefer REST over RPC?
#33I prefer to call my APIs RESTish. That way, I can avoid never ending debates about whether some particular feature of my API conforms to REST.
I like your approach because it avoids never ending debates.
Re: Do you really know why you prefer REST over RPC?
#34For example an API that allows you to get users might also have a job resource or action to perform RPC jobs on the server from a manage api path or similar.
Re: Do you really know why you prefer REST over RPC?
#35Earlier quoted context omitted.
This is my approach as well. Works very well with an event-sourcing model. It is much easier to capture user intent with POST /api/customer/1/change-address-due-to-move { "address_1": "...", "address_2": "...", ... } than with: PUT /api/customer/1 { "address_1": "...", "address_2": "...", ... } Also, GET /api/resource/action is nice place for a payload describing the expected inputs to the action. Link it all togethe…
How about POST /api/customer/1/address {"address": "..."}
Re: Do you really know why you prefer REST over RPC?
#36Hmm. Seems to me that this actually relates well to the object-oriented versus functional programming "debate" - REST deals with things (like OO), RPC deals with actions (like functional). But, in my experience, most requests consist of a "thing path" - host, resource; and then some "function" - get, update, other. POST is then the '=' - it's still a function under the hood, but because of it's commonality and intera…
> REST deals with things (like OO), RPC deals with actions (like functional). I think it's the opposite: REST deals with data, while RPC calls an operation that has side effects on some (potentially) unknown state. Not arguing that one is better just offering my thoughts on the analogy.
Re: Do you really know why you prefer REST over RPC?
#37I might be behind on state of the art these days...but my current api has no GET requests, everything is a POST. So in that term, we are not restful. We had a couple of problems with GET requests: all of our data ended up in the url (we have too much info that has to be passed, we stopped working on some browsers), and the data returned could be cached (which is a HUGE problem for us). Now, POSTs can also be cached,…
For serving a filesystem over HTTP REST is great though. And all that caching stuff comes in handy.
From a practical API standpoint though, having two different encodings (GET in url with url parameter encoding, and POST with form encoded or JSON) is a pain and has caused a number of minor bugs and definitely extra work.
Using HTTP is basically a socket for JSON RPC style calls is I think the most straightforward route. In this you have one RPC per request, POST only, with a JSON request body and JSON response. If you use keep-alive it's similar to a socket but can go through some firewalls a bit easier, and has a built-in framing format and metadata thing. Also it works with existing log monitoring tools and frameworks.
Re: Do you really know why you prefer REST over RPC?
#38Re: Do you really know why you prefer REST over RPC?
#39I generally use a pattern like: GET /api/resource POST /api/resource/action Where 'action' is something a bit more descriptive than 'PUT' or 'DELETE' or whatever. Kind of like an object-oriented api... I'm still always dealing with resources, but I have custom actions for specific use cases.
POST /api/resource;action
As that doesn't pollute the idea that the path itself leads to a resource.
Re: Do you really know why you prefer REST over RPC?
#40I might be behind on state of the art these days...but my current api has no GET requests, everything is a POST. So in that term, we are not restful. We had a couple of problems with GET requests: all of our data ended up in the url (we have too much info that has to be passed, we stopped working on some browsers), and the data returned could be cached (which is a HUGE problem for us). Now, POSTs can also be cached,…
I did the exact same thing in a project of mine. We're shifting away from that and put our data in cookies, so we can cache some of the things our API send out.