Live data from Hacker News

Do you really know why you prefer REST over RPC?

apihandyman.io

41–50 of 124 posts

Re: Do you really know why you prefer REST over RPC?

#41
post #25

Earlier quoted context omitted.

How about POST /api/customer/1/address {"address": "..."}

POST is used to create a resource. PUT is used to update an entire resource. PATCH is to partially update a resource.

Sure, just so long as you realize that is a convention and not a law.

Re: Do you really know why you prefer REST over RPC?

#43

I 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.

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…

Why not PATCH /api/customer/1 {"address_1": "...", "history": "moved", ...} (i.e. send your intent as a parameter that may not necessarily get saved in this resource)

Re: Do you really know why you prefer REST over RPC?

#44
post #3

I 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.

Who would have thought that there's more than one way to skin a cat? Or maybe REST is the best chuck out the rest! Pun intended! I like your approach because it avoids never ending debates.

How about PREST? Pragmatic REST?

Re: Do you really know why you prefer REST over RPC?

#45
The OP has essentially used circular logic: RPC is as good as REST because I know how to use it to address the issues that REST addresses (which I doubt, incidentally).

This to me is like arguing that object-oriented programming isn't really any better than procedural programming because I know how to write well-structured procedural programs. This is completely beside the point, which is that procedural programming as a style tends toward balls-of-mud programs (to simplify things), and object-oriented techniques were conceived of in order to address the characteristics of procedural programming that are the cause of this tendency.

I view RESTful API programming in a similar vein: RPC also has negative tendencies (such as the creation of fragile protocols), and REST addresses many, if not all of those. Most of the time for more people, RESTful techniques will lead to better service and API design than will RPC, just like for most of the people most of the time, object-oriented programming will lead to better programs than will procedural programming.

Re: Do you really know why you prefer REST over RPC?

#46
I think Rest works best in dynamically typed languages as it can be a little less strict on format. I think in typed languages RPC could work out better as you can filter out bad requests quicker with a stricter format. I also think RPC tends to be more brittle to changes just like typed languages :)

Re: Do you really know why you prefer REST over RPC?

#47
Actually, the URL pattern doesn't define if your API is RESTful or not. You can use similar URL patterns in RPC too. This would be non-RESTful:

    POST /users/create
    POST /users/1234/read
    POST /users/1234/update
    POST /users/1234/delete
Also, in REST you don't have to use this URL pattern. Just make sure that your resources have their own URLs. In addition, resources don't have to map into your database. E.g.

   POST /new_address_due_to_move.php?customer_id=1234, 
is RESTful, although a bit of a stretch. My line of thought is that if you would have a separate form in your web page, it should be a separate resource with it's own URL where the form data is POSTed.

Re: Do you really know why you prefer REST over RPC?

#48
post #36

Earlier quoted context omitted.

> 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.

That looks to me like you both agree. Things==data and actions == "calls an operation"

Yes, exactly.

Re: Do you really know why you prefer REST over RPC?

#49

I started developing network apps before REST existed -- probably like many people here, that wasn't long ago, SOAP, various things like RMI and then XMLRPC were things. SOAP was never good anyway, deeply buried in standards committee goo. But there are still things I miss from these things. When I found XMLRPC after doing all these things, it was very much a "WOW" moment. (JSON of course, with it's definite differen…

Yar, in my limited experience with SOAP, it's like Java: Good ideas under the hood, but then the usage you usually see is just /terrible/....

But I really like the idea that the API can tell you about the API, and do kind of wish JSON REST APIs had similar patterns.

I think the main problem that XML runs into is that it's used a data interchange format and/or a data serialization, instead of a markup.

I think the bit you're missing from the XML APIs - that makes you re-implement things - is the lack of an API descriptive document (like the WSDL). If that was a thing, REST is at least as automatically ported as any XML API style. (Someone would still have to write the libraries that turn the document into objects/functions, but that happens with the XML stuff as well)

Re: Do you really know why you prefer REST over RPC?

#50
post #36

Earlier quoted context omitted.

> 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.

That looks to me like you both agree. Things==data and actions == "calls an operation"

The main problem is that function != action.
Post reply on HN