Search code examples
resthttp-caching

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


Solution

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