Common REST Mistakes
prescod.net
prescod.net
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 presupposes a familiarity with REST theory and jargon. And the assertion that 'sessions are irrelevant' instantly raises my suspicions about the author's relationship with reality.
I think when most normal people say REST, they simply mean some sort of vague messages-over-HTTP metaformat that doesn't necessarily enforce odd restrictions about POST vs. PUT, is somewhat self-documenting and easy to work with due to the limited scope of the medium, etc.
And I think of Fielding's dissertation, together with a few RFCs like 2616, as the founding documents of REST.
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.
so you will have something like
<api>
<projects>http://../projects/</projects>
</users>http://../users</users>
</api>
or even this: <service>
<name>projects</name>
<href>http://.../projects/</href>
</service>
...
and then your project list should not just return you projects ids to construct a url with, instead it should provide you full urls to access the relevant resources.The rule of thumb is: with a PROPER REST API you should never do any "url generation", you should get ALL your urls (except for the SINGLE entry one) form the API.
check out this link for some more info: http://www.theamazingrando.com/blog/?p=107
I have a much easier time finding a cut-and-paste error from email in http://bob.com/posts/37/comments/79 than in http://bob.com/postthing/1f724c302a3b69ef9327313adb269a8d, even if the latter is convenient when the site later restructures things or adds a server.
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.)
If not logged in, redirect to a login page (resource) which upon success redirects back, e.g. GET login?next=desired_resource.
If logged in but not authorized to perform the action on the resource return 401.
That's it basically, isn't it? Also not trolling, challenge me if I'm missing something please.
You know, with all the little browser-chrome experiments that have been going on lately, I'm really surprised that no one has tried to make HTTP-authentication-based login/logout/account management as painless as HTML-served variants. I'd imagine that it would couple with the little "lock" icon in the URL/status bar, making it have four states instead of two: "insecure, secure, insecurely logged in, and securely logged in" where clicking on it brings up a menu to both view credentials and change your password/edit profile/log out/close account/sign up/anything else browser makers want to implement. (They could be distinct, of course, but I like the idea of making "insecure" look scary so that users would be deterred from sending credentials through it.
Of course, there can be authentication and authorization but, really, there's no need for a session since you have to do those two on each http request anyway.
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.
That said, yes, everyone seems to forget about hypertext. I'm curious: if I'm building a REST-based JSON-formatted service, what's the convention for returning related URIs? Ex: if I return a Product resource andi want to have links to the products image, the owner's resource, edit this product, and so on, is there a standard way to return them in the JSON structure, or doesthis nor matter?
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 simple as much as possible.
I said simple as possible, but the real world is always complex and one day you may have to use something other than JSON-RPC in which case someone will have to create an adapter or an abstraction. Thankfully this is easy to do in software even if it sometimes looks nightmarish.
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)