tags:

views:

218

answers:

2

I'm about to start developing a REST API for a client's website and I've been doing some research. I came accross this useful SO question on the gold standard for APIs: http://stackoverflow.com/questions/297005

Prior to reading this post I'd thought about using the Flickr API as a point of reference. However this comment on the above question made me think twice:

The Flickr API is particularly hilarious, for example. It advertises itself as RESTful and yet is nothing of the sort! – NathanE

Firstly this suggests that I need to read more about REST till I completely understand it.

I'm particularly interested in what makes the Flickr API not RESTful and what affect these none RESTful elements have. Any insight anyone has would be very much appreciated.

+2  A: 
deamon
Does this mean you can't authenticate a RESTful API? My client needs authentication for some parts of the API. Does the need for authentication mean you should ditch REST all together?
Richard
REST can be used with authentication. To conform with REST principle the authentication should be stateless (without session). Common authentication mechanisms are HTTP Basic and Digest authentication and TLS client certificates.
deamon
With REST the authentication information should be sent with each request, so that each request is independent of previous requests. What you want to avoid is passing some form of session id or token that the server uses to verify if the user was previously authenticated.
Darrel Miller
That's true for Basic Auth, but something like Digest Auth blurs the line a bit.
Mike
+3  A: 

Another important reason this API would be deemed unRESTful is because it doesn't make use of 'hypertext'. Hypertext is simply using links (and link relations) to move clients along in your applications, rather than requiring them to programatically 'construct' a URI.

This is not RESTful:

GET /collection
200 OK

<collection>
  <item>
    <id>1</id>
  </item>
</collection>

This is RESTful:

GET /collection
200 OK

<collection>
  <item href="/collection/1" />
</collection>

The benefit of the latter, RESTful, approach is that your server can move the item resource wherever it wants - e.g. move it to /item/1 - change the href value, and know that all clients will manage the change. The former approach is not capable of this because the server cannot guarantee that all clients will acknowledge the change; this is part of what is referred to as client/server coupling, and in large distributed systems where your API has lots of clients you want to keep this to a minimum - this is the primary objective of REST.

Roy Fielding refers to this part of REST as the 'hypertext constraint', and he wrote the following blog post about it:

http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

Mike
Maybe you could qualify that the first option is not RESTful if the client uses the representation to construct the url '/collection/1' and the media-type retrieved does not specifically allow that kind of URI construction.
Darrel Miller
I wouldn't promote media types being designed that way
Mike