TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

It's time to put REST to rest

72 pointsby kanishkdudejaover 1 year ago

37 comments

angillyover 1 year ago
As a REST enthusiast I was excited to read this and learn a new perspective but this section<p>&gt; The “benefits” REST is supposed to introduce<p>Is one of the more egregious straw men I’ve seen in a while. Never once in my twenty years have I heard anyone say it’s nice because “you don’t have to read the docs” or “it works in a browser”<p>REST helps with lots from thinking through clean data models to helping ensure consistency within an API.
评论 #38798988 未加载
评论 #38799162 未加载
评论 #38798946 未加载
JohnMakinover 1 year ago
&gt; About being able to use a RESTful API directly from a browser: browsers only use the GET and POST HTTP methods, among the ones REST associates meaning to. You cannot use a RESTful API from the browser, because the PUT, PATCH, and DELETE methods are not used by the browser, and even the POST method cannot be used without a UI. Also, even if you could, APIs are for machines, not humans. The user experience would be dreadful if you had to use a RESTful API directly from a browser, without a specific UI for it.<p>This.. isn&#x27;t true?
评论 #38798831 未加载
评论 #38798837 未加载
评论 #38798879 未加载
recursivedoubtsover 1 year ago
OK OK OK, OK OK, stay calm, Carson, stay calm...<p>I&#x27;d like to just leave a few links on REST here for the reader&#x27;s consideration:<p><a href="https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;how-did-rest-come-to-mean-the-opposite-of-rest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;how-did-rest-come-to-mean-the-opposi...</a><p><a href="https:&#x2F;&#x2F;intercoolerjs.org&#x2F;2016&#x2F;01&#x2F;18&#x2F;rescuing-rest.html" rel="nofollow">https:&#x2F;&#x2F;intercoolerjs.org&#x2F;2016&#x2F;01&#x2F;18&#x2F;rescuing-rest.html</a><p><a href="https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;two-approaches-to-decoupling&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;two-approaches-to-decoupling&#x2F;</a><p><a href="https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hypermedia-apis-vs-data-apis&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hypermedia-apis-vs-data-apis&#x2F;</a><p><a href="https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hypermedia-clients&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hypermedia-clients&#x2F;</a><p><a href="https:&#x2F;&#x2F;intercoolerjs.org&#x2F;2016&#x2F;05&#x2F;08&#x2F;hatoeas-is-for-humans.html" rel="nofollow">https:&#x2F;&#x2F;intercoolerjs.org&#x2F;2016&#x2F;05&#x2F;08&#x2F;hatoeas-is-for-humans.h...</a><p><a href="https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hateoas&#x2F;" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;essays&#x2F;hateoas&#x2F;</a><p>In addition, I’d just like to interject for a moment. What you’re referring to as REST, is in fact, JSON&#x2F;RPC, or as I’ve recently taken to calling it, REST-less. JSON is not a hypermedia unto itself, but rather a plain data format made useful by out of band information as defined by swagger documentation or similar.<p>Many computer users work with a canonical version of REST every day, without realizing it. Through a peculiar turn of events, the version of REST which is widely used today is often called “The Web”, and many of its users are not aware that it is basically the REST-ful architecture, defined by Roy Fielding.<p>There really is a REST, and these people are using it, but it is just a part of The Web they use. REST is the network architecture: hypermedia encodes the state of resources for hypermedia clients. JSON is an essential part of Single Page Applications, but useless by itself; it can only function in the context of a complete API specification. JSON is normally used in combination with SPA libraries: the whole system is basically RPC with JSON added, or JSON&#x2F;RPC. All these so-called “REST-ful” APIs are really JSON&#x2F;RPC.
评论 #38799395 未加载
评论 #38798850 未加载
评论 #38799196 未加载
评论 #38801046 未加载
munk-aover 1 year ago
One point this article objects to is the (ab?)use of HTTP status codes for indicating object status (i.e. 404 Your student doesn&#x27;t exist). HTTP status codes are an extremely loose and flexible standard and I think that semantically most of the &quot;RESTful&quot; uses here are perfectly in line with expectations. Shift your thinking for a moment to consider that instead of `&#x2F;user&#x2F;12` linking to a script it&#x27;s actually just a flat file containing some information about the user - the 404 response when the user doesn&#x27;t exist is perfectly reasonable. The requestor shouldn&#x27;t really care whether the request was fulfilled by apache checking file existence or some PHP script. In fact, webservers are just another kind of dynamic responder and it&#x27;s important not to mystify their internal workings.
ilovefoodover 1 year ago
The article is good, and I get the point. However, from experience, this:<p>&gt; POST on &#x2F;queries&#x2F;enlisted-students-on-joining-date&#x2F;version&#x2F;1 { &quot;date&quot;: &quot;2023-09-22&quot; } to retrieve all students that joined on a given date.<p>always ends up in a complete and absolute mess, where every possible query gets it&#x27;s own random name, different parameters, ending up with duplicates all over the place. Also, while it can be possible to cache these POST requests (responses), it&#x27;s additional work and more friction compared to REST. I&#x27;m not convinced the tradeoff is worth it in this particular case.<p>All in all, I don&#x27;t know if the current proposal can be an alternative either but the idea of a &quot;REST-lite&quot; goes in the right direction and it&#x27;s a great start.<p>However this is a complete no for me:<p>&gt; When a requested student is nonexistent, your API can return 200 OK HTTP status code with a { &quot;user&quot;: null, &quot;message&quot;: &quot;No user exists with the specified ID&quot; } response body.<p>If nothing is found, I want a 404! :D
评论 #38799024 未加载
评论 #38799191 未加载
dale_glassover 1 year ago
A thing not being mentioned is caching.<p>Now I&#x27;m not a web dev, I&#x27;ve played around way back in the CGI era and since then moved on to other things. But my impression was that part of the point of REST was making it fit in a bit better in how the protocol is supposed to behave.<p>Early on there was a lot of stuff that did nothing but GET for everything. Done that way any layer in the middle can&#x27;t make any sensible caching decisions, and even the logs are annoying to look at when you can&#x27;t quickly tell apart what&#x27;s retrieving data and what&#x27;s changing it.<p>So my impression was that part of the point of REST is to shoehorn an API into something that makes sense in the way HTTP is supposed to work, and you&#x27;re less likely to have something go dramatically go wrong because some cheap ISP is running a transparent proxy and deciding that the GET that&#x27;s supposed to save something doesn&#x27;t actually need to happen, because look, this user already made a GET to the same URL 5 seconds ago.<p>Now of course today everything uses SSL, but early on it wasn&#x27;t that weird to run into some awful ISP that would do some sort of aggressive caching to save on upstream bandwidth, if not to actually try to recompress stuff in flight.
simonwover 1 year ago
I agree with some of this - I&#x27;ve never found value in the different PUT&#x2F;PATCH&#x2F;etc verbs, and I think the lack of examples of good &quot;pure&quot; REST APIs indicates that pure REST doesn&#x27;t work easily for most projects.<p>I do think this throws away some pieces that are really valuable though:<p>1. URLs for concepts are a good idea<p>2. Distinguishing between read-only operations (which can be cached) and write operations using GET and POST verbs is useful<p>Personally I&#x27;ve found myself settling on &quot;REST-ish&quot; JSON APIs:<p>- Every domain concept has a URL, and a standard consistent JSON representation that&#x27;s also returned by list endpoints<p>- GET for read operations, POST for anything that performs a write<p>- I don&#x27;t like content negotiation via the Accept header, so instead if I need to support alternative representations I&#x27;ll do that using file extensions, .json vs .csv for example
评论 #38799216 未加载
评论 #38801034 未加载
评论 #38798911 未加载
anamexisover 1 year ago
If I had to guess, the comments here are going to revolve around &quot;that&#x27;s not REST&quot; and &quot;where&#x27;s the hypermedia.&quot;<p>I think that ship has sailed. REST in practice just means following HTTP semantics.
评论 #38798843 未加载
评论 #38798886 未加载
评论 #38798883 未加载
评论 #38798854 未加载
catmanjanover 1 year ago
Having used “REST” for 10 years or so I can confidently say I’ve never used REST
评论 #38798845 未加载
评论 #38798794 未加载
altdatasellerover 1 year ago
First put SOAP and GraphQL to rest. Then we can talk
hn_throwaway_99over 1 year ago
While I think some folks are getting caught up in the details, I thought the overall premise of this article was correct:<p>1. First, as other comments here are pointing out, in the industry people use &quot;REST&quot; to mean lots of different things. Some folks just use it to basically mean &quot;An API over HTTP that uses JSON and HTTP methods (GET, POST, etc.)&quot;. For clarification I like to refer to that as &quot;REST-lite&quot;. The author is talking about what I like to refer to has &quot;true REST&quot;, which is strict about entities, verbs, etc. and the format of calls like PATCH.<p>2. I think the authors general points about why &quot;true REST&quot; is usually a bad idea have been proven out, and like most bad ideas that originated around that time period, they came about because people had a fantasy idea of how we would interact with resources on the web that wasn&#x27;t born out in reality. I essentially thought his point about &quot;being able to use any API without understanding it first&quot; was spot on. I also think there were other good points about the supposed benefits that nobody really uses, or that aren&#x27;t that much of a benefit (these days, who really cares about supporting multiple formats of an API like XML in addition to JSON?).<p>At the end of the day, after decades in software development, I&#x27;ve pretty much come to the conclusion that if your API framework doesn&#x27;t look like some flavor of RPC, it&#x27;s bad. This is just fundamentally how most software developers think: &quot;I want to do some operation X, so just let me make a remote procedure call that is named X&quot;. This higher-order structure is usually a mistake that&#x27;s trying to get developers to conform to some ivory tower way of thinking that doesn&#x27;t work.
alexpetrosover 1 year ago
If the supposed benefits of REST are:<p>&gt; 1) It’s simple, and easy to understand. You can perform the same actions on all resources, so you don’t need to learn the details of a specific API to use it. 2) The API is usable via a browser.<p>then the part that this article is missing is HTML. REST APIs require HTML (or equivalent), because (via the the browser) the HTML self-describes what actions can be performed on it. If you return `&lt;a href=&#x2F;profile&gt;My Profile&lt;&#x2F;a&gt;`, then the user knows that clicking on it will take them to their profile; they&#x27;re interacting with the API without knowing its details.<p>A lot of people say &quot;ah to hell with it REST has no meaning anymore&quot; but since the premise of the article is to engage with the meaning of REST, well, that&#x27;s kind of on them.<p>See the @recursivedoubts essays in another comment on this post too, they&#x27;re much more in-depth than my comment.
senderistaover 1 year ago
I thought a practical benefit of REST (probably the only one I really care about) is that it makes APIs more scalable by allowing caching proxies to safely cache responses to GET requests? At least I thought that was a big part of the original pitch, but I don&#x27;t see it mentioned here.
elanningover 1 year ago
I’ve been having a good time using REST level 0.5<p><a href="https:&#x2F;&#x2F;faithlife.codes&#x2F;blog&#x2F;2023&#x2F;09&#x2F;rest-level-zero-dot-five&#x2F;" rel="nofollow">https:&#x2F;&#x2F;faithlife.codes&#x2F;blog&#x2F;2023&#x2F;09&#x2F;rest-level-zero-dot-fiv...</a>
评论 #38798860 未加载
mpweiherover 1 year ago
Those 2 were never the claimed benefits, and the fundamental &quot;problem&quot; is not a problem: a LOT of data processing is making changes to records. And you can encapsulate a lot of logic behind making changes to records.<p>And this makes most software easier to understand:<p>&quot;Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won&#x27;t usually need your flowcharts; they&#x27;ll be obvious.&quot; -- Fred Brooks
jauntywundrkindover 1 year ago
I was pretty annoyed expecting some awful conclusion that we had to do something entirely different, resting upon what felt like extremely shaky grounds. A one-auarter decent OpenAPI will elaborate what endpoints do, which felt like all that was missing.<p>In the end though, the author isn&#x27;t really arguing against what we have, expect they want &#x2F;commands and &#x2F;queries prefixes.<p>Given the way some endpoints can be overloaded with disparate behaviors, I don&#x27;t disagree that sometimes it can be confusing for all the verbal to apply to an endpoint. But <i>POST &#x2F;students&#x2F;enroll</i> seems more than fine to me, and trying to wrestle out a new norm, where URLs aren&#x27;t broken down by resource type but are broken down instead by behavior-class seems absurd &amp; a folly.<p>&gt; <i>The fundamental issue with REST is that it defines operations that manipulate data structures. It’s about structure and structural changes, not behaviour. It’s imperative, rather than declarative.</i><p>If it&#x27;s about structure, wouldn&#x27;t that be declarative? Aren&#x27;t behaviors typically imperative (move this here, drive that there)?
Humphreyover 1 year ago
The author has almost perfectly described the pattern behind GraphQL mutations!<p>That is, a command on the server that represents a user action, takes input, and returns the updated data that has changed. While many people dislike the whole GraphQL stack (I love it, it solves all the problems the author has with REST), I think we can all agree with the usefullness of the pattern that mutations are built upon.
hinkleyover 1 year ago
If you’re designing something right now, I want to remind you of one piece of shared but uncommon wisdom:<p>So many of your users will not make it much past the elevator pitch for your idea. They will feel willfully or even recklessly entitled to the notion that if your tool allows something, the.n it was <i>meant</i> to be used that way.<p>I don’t have any quick fixes for that. I doubt they exist. There are some very clever things I have seen in the REST domain that are lumped under advanced topics that make a lot of sense but I don’t think I have ever seen in the wild. So if an idea feels important, you have to aim it at the journeyman if you expect it to be used at all, and beginner if you can figure out how without losing them.
fabian2kover 1 year ago
There are some things that simply don&#x27;t fit into the REST structure, the most common one for me is bulk operations. Operating on multiple instances of a specific resource is a common thing, and you need a non-REST endpoint to do it properly. Of course you could just iterate over the items, but then you can never have transactional behaviour (either no write happens or all of them happen). And of course it&#x27;s terribly slow for larger number of items.<p>Another annoyance is GET endpoints with complex filters like e.g. the index route for a specific resource. It&#x27;s really annoying to be limited to the query params instead of a request body for that.
ilakshover 1 year ago
People will still be arguing about this in ten or twenty years when many new services use AI agents on a blockchain that automatically pick up DSLs invented a few days before by other AI agents and use them to negotiate and execute service orders on your behalf.<p>Eventually you may get something like a high dimensional protocol used for converting and syncing neural adapters on the fly, enabling &quot;multi-brains&quot; to collaborate opportunistically. But even then there will _still_ be people having this exact same argument.<p>Anyway, I feel like a lot of people actually moved on to GraphQL years ago. I think I probably need to catch up to that trend still.
monero-xmrover 1 year ago
Rest is fine, just a loose standard around using HTTP for rpc calls. Makes communicating between different servers and languages easy.<p>The real mistake is graphql. Like microservices, so many companies get hamstrung with this. I’ve said my piece.
agraddyover 1 year ago
I went into this article strongly disagreeing but I think the alternative presented at the end are valid ways to structure an API and for those who very loosely follow REST structuring would probably consider the alternatives &quot;REST&quot; too.<p>REST seems to have different definitions depending who you talk to. Some define it very strictly (as the opening of the article seems to do) and others define it very loosely (as a JSON interface with GET&#x2F;POST&#x2F;etc commands). For those who implement REST loosely, the suggested alternatives fit right in.
Kwpolskaover 1 year ago
&gt; So when the server receives a PATCH &#x2F;schools&#x2F;{school-ID}&#x2F;students&#x2F;234 { &quot;lastname&quot;: &quot;Luthor&quot; } request, it needs to understand that a student has requested for their lastname to be changed, and it then needs to decide what to do about it. What if some fields cannot be changed? What if the value of some fields is constrained by the value of some other fields? By allowing an arbitrary PATCH operation, these concepts are hard to model and validate requests against.<p>If there are validation issues with user-provided data in a PATCH, then the API should tell the user what they did wrong and reject the update, plain and simple. How would their solution react to bad data? How would it be different from what any implementation of PATCH does?<p>&gt; POST on &#x2F;queries&#x2F;enlisted-students-on-joining-date&#x2F;version&#x2F;1 { &quot;date&quot;: &quot;2023-09-22&quot; } to retrieve all students that joined on a given date.<p>So instead of a browser-accessible GET with idempotency standards, you need a POST and you need to serialize JSON just for a single field?<p>&gt; POST on &#x2F;commands&#x2F;report-student-lastname-change&#x2F;version&#x2F;1 { &quot;student-id&quot;: &quot;123&quot;, &quot;new-lastname&quot;: &quot;Kent&quot; } to report a lastname change for a student.<p>Great naming: I initially thought this would be about a report about last name changes, not a way to add new data.<p>Should there be separate endpoints for each field of each entity? That might replace “validation” of no changes to fields that cannot be changed, but it does not replace validation of last-name-is-not-empty or national-id-number-is-valid. What if the changes are provided in a form that allows to edit all data? Do I need to send separate commands for each user-edited field? If using the bulk form (POST &#x2F;commands), what if one of the commands fails — will the previous commands be rolled back, or will the DB end up with partially-edited data?<p>&gt; When a requested student is nonexistent, your API can return 200 OK HTTP status code with a { &quot;user&quot;: null, &quot;message&quot;: &quot;No user exists with the specified ID&quot; } response body.<p>And now you can’t even automatically detect error conditions and have consistent handling for them, at least not with a schema like this.
desultoryover 1 year ago
Nice article and the examples are much appreciated. I&#x27;ve read about this concept under the terms CQS and CQRS before.<p>1. <a href="https:&#x2F;&#x2F;khalilstemmler.com&#x2F;articles&#x2F;oop-design-principles&#x2F;command-query-separation&#x2F;" rel="nofollow">https:&#x2F;&#x2F;khalilstemmler.com&#x2F;articles&#x2F;oop-design-principles&#x2F;co...</a><p>2. <a href="https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;CQRS.html" rel="nofollow">https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;CQRS.html</a>
TOGoSover 1 year ago
&gt; I even used HATEOAS principles when building HTTP APIs<p>I found your problem.<p>&gt; About being able to use any API without understanding it first<p>That&#x27;s a HATEOAS thing, as I understand it. REST just means that you have resources and verbs, and the verbs have ~relatively~ consistent meaning. If I see some GETs and PUTs and PATCHes and DELETEs I can get a pretty good idea of what&#x27;s going on. It doesn&#x27;t mean I understand all the details of your application logic.
ath3ndover 1 year ago
No, it&#x27;s not.<p>But in short, articles arguing thst the most popular api format needs to be put to rest can&#x27;t be anything else but highly opinionated clickbait
kolanosover 1 year ago
The solution in this article looks a lot like GraphQL. Commands are mutations, queries are... well, queries.
commandlinefanover 1 year ago
It drives me crazy that every RESTful API I&#x27;ve ever seen in the wild has been running under a full-blown Tomcat or nginx (or some equivalent) web server when only a tiny, tiny subset of the HTTP protocol is actually needed for the API being supported.
gregorsover 1 year ago
there&#x27;s a reason why REST is still the most widely used and the RPC type examples have faded.<p>Here&#x27;s the thing, domain specific language specification both in source code and at various API interaction points are a good thing. But they are a thing that takes time to figure out, and they have a tendency to change. REST is still the best starting point and I challenge anyone to say that RPC is &quot;better&quot;. We&#x27;ve tried it before it wasn&#x27;t better. Oh you mean we did it wrong? Well now, that&#x27;s the real trick isn&#x27;t it?
mgaunardover 1 year ago
The trading example is bad, since we do talk about posting limit orders even outside of a REST context -- though it refers to it staying in the book and not matching immediately.
quickthrower2over 1 year ago
REST is a design pattern. Do you use the bridge pattern for all your Java code? Nah! Do you use an ORM for all your data access and never drop down to SQL? Nah.
baqover 1 year ago
<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;XML-RPC" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;XML-RPC</a> (1998)
评论 #38798816 未加载
评论 #38798874 未加载
nightowl_gamesover 1 year ago
Let&#x27;s put &quot;REST&quot; to rest because no one can agree on what it means.
grishkaover 1 year ago
I&#x27;ll have to add a client API to one of my projects soon and I&#x27;ve been thinking about this particular problem lately.<p>The one API I worked with a lot is that of VKontakte. It&#x27;s as unRESTful as they come. You send requests to URLs like api.vk.com&#x2F;method&#x2F;users.get. The HTTP method doesn&#x27;t matter at all, how you pass parameters doesn&#x27;t matter at all (can be a combination of query and form-data for all it cares), the version is just `v` parameter, the access token is also just a parameter, and errors come with 200 OK. That is kinda not well thought out. But only kinda.<p>The one I&#x27;m contemplating is somewhere in between the two. The endpoints are still &quot;methods&quot;, but the HTTP method does have a meaning: GET is for retrieving something, and POST is for active actions. The access token will have to be passed in Authorization header. The version will still be a `v` parameter. There will not be any IDs in the paths because of how awkward that is. The errors will set the HTTP status code.<p>Any opinions on this?
pentaphobeover 1 year ago
A few really appealing points and ideas here!<p>Versioned &quot;commands&quot; are an improvement I&#x27;d like to see more of (it could even be useful in existing REST-lite APIs - I&#x27;ve used similar concepts to this in some prior work)<p>And the key point around business logic being misrepresented is definitely worth a ponder.<p>Notable that a lot of this sounds like a reinvention of DDD (Domain Driven Design) concepts - or at least if the author is applying DDD they make no mention of it. Which I wholeheartedly support..<p>Seems like two problems being conflated though:<p>1. Low level interactions - generally between systems. Sometimes I _want_ my API not to hold any high level business logic. It&#x27;ll do basic verification of individual entity events (changes) to avoid epically stupid mistakes, but otherwise is a dumb resource used by other, more high level controllers.<p>Often this scenario is basically a thin wrapper over storage mechanisms, or a single abstraction atop a collection of other APIs In this scenario, REST or other &quot;non-business-aligned&quot; options are perfectly fine - if they were any higher level then I&#x27;d be constraining the possible actions to what&#x27;s implemented in a single place.<p>But by keeping it granular, and aligned explicitly to direct interaction with specific models (in a bounded context) then those changes _should_ be isolated.<p>2. Intent based APIs which perform high level actions that are aligned to ubiquitous language.<p>These would be a great fit for the proposed method in the article - and I&#x27;d posit that many of us already use some form of this in our APIs, whether through naughty blurring of what &quot;REST&quot; is supposed to mean, using GraphQL, or other similar alternatives.<p>Generally these are user facing, or at least are at the boundary.<p>Personally I&#x27;d maintain these as a separate thing (or at a separate top level route) which leverages the lower level interfaces to perform more complex, potentially multi-modal activities.<p>---<p>*TLDR* what the article proposes seems useful, but (IMO) more as a good reminder to be clear about your APIs&#x27; purposes: are they an interface to a bounded context, a model, or an aggregate?
ysavirover 1 year ago
What the author seems to miss is that a &quot;resource&quot; in the REST sense (in practical usage at least. I&#x27;ll leave the official recommendation pedantry to those who care for it more strongly than I do) doesn&#x27;t need to reflect a data structure.<p>It&#x27;s definitely <i>easier</i> to link data structures to REST commands--I imagine REST was created with them in mind--but the recommended &quot;commands&quot; can still be thought of as resources. Not every REST verb applies to them, true, but that&#x27;s not really impactful or relevant. The point is that you can continue structuring your API in typical REST fashion, but with the addition of command-oriented RESTful paths that implement the appropriate verbs for that command.<p>The author&#x27;s own suggestion, `POST on &#x2F;commands&#x2F;{command-type}&#x2F;version&#x2F;{command-version}`, is still effectively REST as far as I&#x27;m concerned, with the identifier being a string (&#x27;command-type&#x27;) instead of a number or UUID. The structure of the API hasn&#x27;t changed, we just broadened our definition of a resource. Purists might disagree there, but from a day-to-day practicality perspective, nothing significant changed in our API development. The article is arguing semantics rather than actually criticizing REST as it&#x27;s used in practice.<p>That said, the author does seem to have listed a few things I disagree with:<p>&gt; So when the server receives a PATCH &#x2F;schools&#x2F;{school-ID}&#x2F;students&#x2F;234 { &quot;lastname&quot;: &quot;Luthor&quot; } request, it needs to understand that a student has requested for their lastname to be changed, and it then needs to decide what to do about it. What if some fields cannot be changed? What if the value of some fields is constrained by the value of some other fields? By allowing an arbitrary PATCH operation, these concepts are hard to model and validate requests against.<p>I&#x27;m not sure what difficulty they&#x27;re seeing here. If some of the values can&#x27;t be changed, it&#x27;s a failed request, return the errors without any updates. The &quot;arbitrary&quot; parts feel like they derive more from their own API implementations than anything practically REST-ful. Or maybe it&#x27;s in the official REST spec, which, as comments here demonstrate on repeat, holds very little ground.<p>&gt; This also sucks, because HTTP status codes are about the HTTP protocol, not your business semantics. The 404 Not Found status code indicates that a path doesn’t exist. If you use it to say that a student doesn’t exist, these two get mixed up. If a client invokes the wrong path by mistake, there’s no telling whether it’s due to a protocol error or to a nonexistent student.<p>If there&#x27;s no student with the ID 4, then the path `&#x2F;students&#x2F;4` doesn&#x27;t exist. It&#x27;s not saying that `&#x2F;students&#x2F;&lt;id&gt;` doesn&#x27;t exist, because the path-with-variable only exists as a theoretical construct, not an actual path. So I&#x27;m not quite seeing their argument here (unless, again, they&#x27;re arguing against the semantics of the official recommendation, which I&#x27;ve never seen implemented in a straight fashion anywhere). And if there&#x27;s user error in invoking the wrong path, then that&#x27;s hardly on the API design.
gtirloniover 1 year ago
FreeBSD and REST should organize the Is It Dead Yet? conference.
评论 #38802851 未加载