Live data from Hacker News

Common REST Mistakes

prescod.net

21–30 of 41 posts

Re: Common REST Mistakes

#21

I believe #3 is actually a cornerstone of modern Ruby on Rails usage :-)

I have not read Roy Fielding's dissertation, and so I am speaking out of partial ignorance. But isn't most of this the opposite of what REST is supposed to be? URLs aren't supposed to represent resources? Whahh?

Re: Common REST Mistakes

#23
post #21

I believe #3 is actually a cornerstone of modern Ruby on Rails usage :-)

I have not read Roy Fielding's dissertation, and so I am speaking out of partial ignorance. But isn't most of this the opposite of what REST is supposed to be? URLs aren't supposed to represent resources? Whahh?

That is not exactly what was said. The idea is that URLs are not the same as resources, and that similar URLs do not necessarily imply a relationship between two resources.

Re: Common REST Mistakes

#24
post #21

I believe #3 is actually a cornerstone of modern Ruby on Rails usage :-)

I have not read Roy Fielding's dissertation, and so I am speaking out of partial ignorance. But isn't most of this the opposite of what REST is supposed to be? URLs aren't supposed to represent resources? Whahh?

The contents of URL strings are not supposed to represent resources -- If a client of your "REST API" needs to concatenate strings together to form new URLs based on an out-of-band 'specification', YOU'RE DOING IT WRONG

Repeat after me: Hypertext. Is. The. Engine. Of. Application. State.

URL strings should be completely opaque -- you should be finding link to new resources in other resources, not constructing them yourself (query strings added to found resources are permitted).

The whole "meaningful URL" thing is a strong signal of False REST, and it infects the Rails ecosystem pervasively. REST has nothing to do with your oh-so-clever request routing rules.

Re: Common REST Mistakes

#25

Since a number of people have mentioned point #6 (Sessions are irrelevant), I have a question: Can anyone point to a concrete, more detailed discussion of how to do authentication and authorization in a RESTful manner? I may be missing something very obvious, but I just don't see how this should/can/might look. (Just to be explicit, I'm not trolling. I'm confused.)

One way to do this is to have the clients pass the authentication information in the headers with every request.

Re: Common REST Mistakes

#26

He lost me at 'use PUT and DELETE'. There's a whole range of clients (eg most browser's XMLHttpRequests, Flash) that don't support anything but GET and POST.

Not true, XHR allows to use DELETE and PUT without any problems.

But yes - Flash can only use POST and GET (or maybe only POST? It's been quite a long time since I used Action script)

Re: Common REST Mistakes

#27
post #20
post #16

REST has always felt a little bit dirty to me; an improper commingling of what should be two different layers. To me, using aspects of the HTTP protocol to have meaning for a higher level service is a bit like using aspects of the TCP protocol as part of the HTTP definition, where in a more ideal setup they should be independent, but layered on top of one another. Almost all of the REST mistakes mentioned in this art…

I think you might be wrong about the 'underlying protocol'. HTTP is an application layer protocol. If something feels dirty it is to put another protocol on top of it especially if it doesn't add value. With REST, you are not adding more special meaning than the HTTP methods. Using those methods according to the spec is all there is to it. If that's enough to do your business, why add more to it? Things should be sim…

Simplicity is good, but so is flexibility and compatibility. As I mentioned, parts of REST aren't good enough; anything that doesn't have access to http status codes won't be fully compatible. A decent RPC protocol like JSON-RPC is both flexible and simple. An added bonus to not marrying your protocol to http is that your API will work seamlessly over other protocols should the need arise. I have an API that was originally intended for web clients, but later the need arose for some internal tools to be able to call the same methods remotely and asyncronously. Instead of going over http, the jobs are submitted to gearman in JSON-RPC format and everything works without having to modify the server or unnecessarily and inefficiently route the calls externally through apache.

Re: Common REST Mistakes

#28
post #26

He lost me at 'use PUT and DELETE'. There's a whole range of clients (eg most browser's XMLHttpRequests, Flash) that don't support anything but GET and POST.

Not true, XHR allows to use DELETE and PUT without any problems. But yes - Flash can only use POST and GET (or maybe only POST? It's been quite a long time since I used Action script)

I think he means HTML forms. PUT and DELETE are broken in at least some (even modern) browser implementations.

Re: Common REST Mistakes

#29
post #24
post #21

Earlier quoted context omitted.

I have not read Roy Fielding's dissertation, and so I am speaking out of partial ignorance. But isn't most of this the opposite of what REST is supposed to be? URLs aren't supposed to represent resources? Whahh?

The contents of URL strings are not supposed to represent resources -- If a client of your "REST API" needs to concatenate strings together to form new URLs based on an out-of-band 'specification', YOU'RE DOING IT WRONG Repeat after me: Hypertext. Is. The. Engine. Of. Application. State. URL strings should be completely opaque -- you should be finding link to new resources in other resources, not constructing them yo…

Can you explain more? It seems like you're saying that RESTful APIs should somehow be self-documenting, and that there should be no need for an API specification. I've never heard this argument before and would love to know more.

Re: Common REST Mistakes

#30
post #11

Several of these points are highly prescriptive without offering any motivation for the advice. For example, "your public API should not depend on the structure of your URIs. Instead there would typically be a single XML file that points to the components of your service." It's difficult to understand this kind of point without an example in hand - preferably an example taken from an actual website. The whole list pr…

By "sessions are irrelevant", he basically means "don't recreate circuit switching on top of your packet-switched TCP/IP connection." Each HTTP request should carry with it all the state required to do what it needs to do (including state stored in cookies et all); it shouldn't be dependant on what has come before or what will come after it.

Right this is a huge item when it comes to scalability. I argue this with developers all the time. The problem is that session is like Crack, it starts with just a little. It is so easy to get caught up in storing off some info in a property bag or List for later use, but it binds you to so much hardware and software infrastructure, by using just one little pattern.

I am old enough to remember the first time the session pattern was used in a web framework, I remember cringing then just as I do now when I see it used.

Post reply on HN