Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: Should I redirect to the version URL of an entity?

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.)

like image 714
sfussenegger Avatar asked Apr 02 '10 16:04

sfussenegger


2 Answers

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.

like image 94
rytis Avatar answered Sep 18 '22 14:09

rytis


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.

like image 32
rjh Avatar answered Sep 19 '22 14:09

rjh