3 ms·
Yes, Fielding's dissertation backronymed the HTTP protocol into REST, but the concept of resource driven design also exists. The benefits of applying the REST
by rswail 5y ago
Yes, Fielding's dissertation backronymed the HTTP protocol into REST, but the concept of resource driven design also exists.
The benefits of applying the REST style is:
1. Limiting the verbs makes you focus on the nouns (URIs) and the description of them.
2. REST verbs do NOT "map" to CRUD in a database. This is overloading the REST style to match a server's implementation. What or how a server (or client) maintain the state of a resource is up to that server/client.
3. HATEOAS is not really achievable for naive clients. Browsers "expose" the links to the human user to enable the user to navigate. HTML provides the particular media type to expose that navigation.
4. If a server and clients agree on a media type, then as part of that agreement is the interpretation of attributes, like "link" elements with "rel" and "href" attributes.
5. RPC (whether as ONC-RPC, CORBA, XML-RPC, JSON-RPC) etc is brittle. It usually requires both the client and server to upgrade their understanding of the interface simultaneously and makes it hard to version or separate the system elements. This lesson has to be learned over and over as programmers realize that "remote" procedure calls are not local and can't use the same semantics.
6. The process I've followed (successfully) is:
* Define a "well known" URL. I use "/versions" that returns a media type that describes the available API versions, attributes of them like "not before" and "not after" and a versioned endpoint for subsequent usage. This allows clients and servers to evolve independently. The versions follow semver, so it's clear when there's breaking and non-breaking changes.
* Define resources in terms of their state (via a FSM) and transitions. Map the transitions to HTTP verbs, along with media types that describe the change in state.
* The transitions should be expressed in terms of the resource, not CRUD. Don't talk about "Create Account", you "open" an account. In business terms, it is very rare that you "delete" something. In addition, HTTP semantics means that you can't return a message body for the DELETE verb.
* Using PUT vs PATCH can be avoided by exposing the things that you want to "PATCH" via sub-resources in the URL pattern (or appropriate HREFs in the parent resource). Including the sub-resource attributes in the parent (when you GET it for example) should be selectable via a query parameter on the GET. However, where possible, use GETs of the sub-resources and cache them appropriately.
The net result is that you have an API that is consumable mostly automatically, with the agreed media types defining the necessary navigation.
I've never used downloadable code as it hasn't been necessary, but it's relatively easy to see how to extend the media types to include links to the code (ie the equivalent of <script> tags).
Unfortunately protobufs have re-introduced the concept of RPC style APIs and they absolutely suck, even if protobuf does allow you to version the messages. You still need to exchange the proto headers and recompile code to update.
It's still brittle RPC underneath, because programmers can't be assed dealing with network failures or other issues or with proper internal versioning of the underlying implementations.
There's really no need for most use-cases to use anything other than HTTP, the standard verbs and their interpretation, URLs (potentially with patterns but avoidable with proper links), and JSON media types/schemas. Compression of the JSON makes it mostly equivalent to protobuf on the wire, HTTP/2 etc avoids the single threaded nature of the HTTP TCP connection.
- Toutouxc 5y agoSounds to me like you're listing the benefits of the FIOH (as used in the article) style, i.e. using HTTP verbs to manipulate (reasonably named, nested) resources (which often, but not always, maps to CRUD actions on your database models), as opposed to the RPC style. The main issue that we're doing FIOH and calling it REST, which makes internet arguments about RPC vs FIOH harder and confuses the hell out of newbies who are told to go and build a "REST API".
- rswail 5y agoAgreed, "REST" as we generally use it is actually "RDD" or "ROA" (Resource Driven/Oriented Design). Use of HTTP as the protocol is a "side effect" that happens to map nicely. [1] But it's more than that, especially if you design using resources, finite state machines and transitions. That's independent of protocols or anything else. Once you have that defined, the infrastructure often "falls out" and you have APIs that are reasonable, as well as working well into CQRS and Event Sourced implementations. A lot of this stuff was thrashed out on that yahoo group, which happened around the same time as "AJAX" became the latest buzzword. I think of RPC as "The verb is important, not the noun", whereas REST/ROA is "The noun is important, not the verb". [1] https://www.developer.com/web-services/overview-of-resource-oriented-architectures/ https://www.developer.com/web-services/overview-of-resource-...
- DeathArrow 5y ago> RPC (whether as ONC-RPC, CORBA, XML-RPC, JSON-RPC) etc is brittle. It usually requires both the client and server to upgrade their understanding of the interface simultaneously and makes it hard to version or separate the system elements. This lesson has to be learned over and over as programmers realize that "remote" procedure calls are not local and can't use the same semantics. Using "REST" for communication can be brittle too, since you have to update the contracts in both "client" and "server".