views:

179

answers:

5

I am currently working on a REST service. This service has an entity which has different versions, similar to Wikipedia articles.

Now I'm wondering what I should return if for

GET /article/4711

Should I use a (temporary) redirect to the current version, e.g.

GET /article/4711/version/7

Or should I return the current version directly? Using redirects would considerably simplify HTTP caching (using Last-Modified) but has the disadvantages a redirect has (extra request, 'harder' to implement). Therefore I'm not sure whether this is good practice though.

Any suggestions, advise, or experiences to share?

(btw: ever tried search for "REST Version"? Everything you get is about the version of the API rather than entities. So please bear with me if this is a duplicate.)

+1  A: 

I think it would be more restful to return a list of the revisions for:

GET /article/4711

You could also have:

GET /article/4711/current

Which returns the current version directly.

Brian R. Bondy
`/current` sounds like a good idea. I though about using `/article/4711/version` to get a list of all versions (much like a directory index). Does this sound restful to you?
sfussenegger
+2  A: 

Depends on your intended behavior for GET /article/4711. If it is intended to always point to the latest version, then it should return the latest version directly. Redirecting to a particular version seems problematic as you are relying on the user/client library to not visit that particular URL in the future. To translate into HTML terms, a user might bookmark the version/7 URL and be surprised that they are now accessing an older version instead of the up to date version they originally typed into the address bar.

rjh
I'm not to much concerned about users as the API is XML/JSON only - I know it was only an analogy though ;) I'm not sure if I should consider clients behaving this way. Clients "bookmarking" the location of a temporary redirect are certainly not doing what they are supposed to do.
sfussenegger
So what's the behavior of an XHTTP client in a redirect like this? I feel a little ignorant even asking this question. I assume the browser is smart enough to transparently do the redirect, but I know IE has surprised me with less desirable behavior than this.
altCognito
@altCognito that's what I was wondering too (it's "harder' to implement" with dump clients). Does somebody have any experience with this?
sfussenegger
+11  A: 

If you treat versions as entities (which by the looks of it you do) this is what I'd suggest:

GET /article/4711

returns a list of all versions (and links to them). Which makes /article/4711 a container entity.

GET /article/4711/latest

returns contents of the latest version. You might want to consider /version/latest to get in-line with the below.

GET /article/4711/version/7

returns the specific version of the article.

pulegium
+1 that is much more in line with REST.
rjh
1) "/latest" in deed sounds nice. 2) I thought about using `/version` for a list of versions (much like a directory index of contained files). 3) why wouldn't you redirect from `/latest` to `/version/7`. Doesn't it make much more sense if both are the exact same thing? Maybe I'm wondering as I have slight SEO background that makes me shy away from "duplicate content" ;)
sfussenegger
i'm generally against redirects in APIs and judging by your comment in another answer "I'm not to much concerned about users as the API is XML/JSON only" these pages/URLs aren't for humans... :) In APIs generally it's better to avoid complexities such as redirects as some clients may not be that sophisticated/flexible to handle those. If you're still concerned about SEO/google thing, just add the latest/ URL into robots.txt and tell google to ignore it.
pulegium
Http redirects are how you redirect to latest versions without breaking caching. Most clients implement redirects transparently, and doing it manually is trivial, so wouldnt' recommend against it. It's a great way to provide Hyperlink support to a ReST API.
serialseb
+1  A: 

You might want to look at http://tools.ietf.org/html/draft-brown-versioning-link-relations .

Using the CMIS link relations and the HTTP Link header you can make /article/4711 the latest and provide a link to the versions, e.g. Link: </article/4711/versions>;rel=version-history

Jan Algermissen
+1 interesting link, thanks a lot
sfussenegger
+1  A: 
Chris McCauley
HATEOS is the way to go in this case.
Brian Clozel