General principles for good URI design for RESTful and HTTP applications
stackoverflow.com
stackoverflow.com
Glad to see that - I'm seriously puzzled by the number of references I see to "RESTful URIs".
Exactly my thoughts, the submission title had me prepare a facepalm, but the linked comment is very good.
The canonical example is the "collection" URI,
http://example.com/resources/
And the "element" URI, http://example.com/resources/item17
Would anybody balk if all my REST API's URIs where obscure hashes?So my collection is now,
http://example.com/b9cbc0a72a17e6b9e271187096c3b981269554fb
And the element is, http://example.com/7c2186f626d0aa7dedc0bb7537b578937015ff6e
Is this no worse or better?Pedantic wanks "no worse".
People working in reality "wtf would you ever do that?"
It's only confusing if you think REST nebulously means merely "good web API design" or "good usage of HTTP."
Even though the actual call to the REST service is opaque there is always a person that creates the calling application. Design an API that you would like/enjoy developing against.
Because these guides are written for people who don't understand what they're talking about?
> Would anybody balk if all my REST API's URIs where obscure hashes?
> Is this no worse or better?
In terms of "RESTfulness" there is no difference whatsoever.
In terms of clarity, readability and debuggability, the former is better.
Would this be the exception to the rule or is this problem totally unrelated to REST?
BTW: I'm not debating, I really wanna know.
Sure, just wanted to make my point. In reality you move the subscriber from "subscribed" to "unsuscribed" or something like this...
If the link is in an email, a form probably won't work. Email clients are still worse than browsers when it comes to styling buttons to look like links. In that case, you can use a real link, but add the _method=DELETE to the url parameters. You service can then look for _method on GET requests too. But it's bad and hacky to change a GET into a DELETE, so you really should just use the link to display a web page, then delete with a DELETE or POST from there. That's what most unsubscribe links in emails do anyway.
"Should not" used in the rfc2119 definition. There are always exceptions.
I can see the benefit of doing some of the things on the list, but I never understood what's the motivation behind these two suggestions. What are the practical benefits? (Specifically, what are the benefits for a web application, rather than a web app?)
I can give you some considerable benefits of doing the opposite. My favorite URL scheme looks like this: "http://example.com/?Class.method.id.parts¶m=x.
It enables automatic routing without the need to write explicit, case-by-case routing logic or .htaccess files. It doesn't mess up the base path, so I don't need to do some magic when writing URLs. Moreover, it's straightforward. It's easy to see what's going on on the web pages, in the code and in the logs, because knowing a URL means immediately knowing which controller and action are involved (which is not the case with clever resource-mapping schemes).
There are interesting cases, though, where multi-selecting items and then acting on them could require using a query parameter. "action=remove", "action=update", "action=validate" or something like that.
When dealing with singular resources - it's much easier to follow the HTTP methods and verbs but I'm still at a loss for how to handle multi-select cases where you can't represent 20,30,100+ items as a single resource in the URI.
This, is only in the case of a user's UI web experience and not an API - because I haven't figured this part out yet, I haven't supported batched actions like this in the API (haven't needed to, but it could be useful?).
More generally, a GET must not alter application state. It can change a cache or a logfile (these are either implementation detail or irrelevant), but if there is any way for the user to see what was changed, then it does not belong in a GET[0].
[0] things like consumption quotas management are of course a different matter, but they're meta-data more than application state.
1. In a browser, the link would lead to a confirmation page POSTed to the server
2. In an API, there's no real sense in doing that, but it'd probably be a DELETE on the subscription resource.
That breaks (and likely is broken already in practice) when pages don't respect semantics of GET and unsubscribe/verify, etc. when page is merely displayed.
Point is, proper handling of GET, POST, PUT and DELETE is all about what you do when receiving those requests, not about the way you compose your URLs. At least that what it seems to be. If I'm wrong, I would very much like to hear why.
But you want to DELETE the actual article, not its deletion page ;) More specifically, if the client is reading an article in some URL, he shouldn't need to find out what's the special deletion URL. It leads to more brittle and less generic clients, with more work for the developer.
Point is, proper handling of GET, POST, PUT and DELETE is all about what you do when receiving those requests, not about the way you compose your URLs. At least that what it seems to be. If I'm wrong, I would very much like to hear why.
I think you're right if the goal is to abide by the REST constraints.
http://example.com/articles/3423423 http://example.com/reviews/fallout-new-vegas http://example.com/bob/submissions/articles/13
They might look different and only some of them might be DELETEable. (Or am I wrong here? I'm not entirely sure.) How that's different from treating http://example.com?Articles.delete.1 as a deletable representation of the same article? Both will affect many other pages on the website. You still need to understand what the request means to really know the consequences of sending it.
In short, I don't think there is anything particularly wrong with doing URLs the way I described.
Practical reason: because browsers have prefetching systems that might GET resources without asking the user, which might be authorized anyway.
Way to expose internal details about your implementation, though.
I mean, you can, but why would you?
http://site.com/generate;lang=en,size=32,weight=78
RESTful Web Services Cookbook[1] gave me the idea (a fantastic book) and what I like about it, is that interstitial proxy software seems to molest the URL less where as some refuse to pass through query string params for some reason (e.g. CloudFront).Anyone see any glaring issues with this?
[1] http://www.amazon.com/RESTful-Web-Services-Cookbook-Scalabil...
I quote it, because it resonates with a lot of people. Especially those who abhor the factoryfactories. Why are the nouns undisputed when it comes to REST? It might map to the web, but does it map well to computing?
I forgot about 2?? responses other than 200, going to implement that now. Also going to implement 418 just because it's fun.