Cover by Subbu Allamaraju

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

11.6. How to Take Snapshots of Resources

This recipe describes how to take a snapshot of the resource before each update. When a client updates a resource via the method PUT, the server updates the current state of the resource, leaving no way for the client to know what existed before the update. However, there are cases when clients expect to be able to go back in time and browse through the history of changes.

For example, imagine that you are designing a web service to provide past and present snapshots of traffic conditions at certain intersections. Most clients would like to see the latest conditions, but some clients may want to browse through past traffic conditions.

Alternatively consider a wiki. For each page on the wiki, the server needs to maintain a revision stack of current and past revisions for each page so that any client can retrieve, compare, and evaluate changes made to any given page.

Problem

You want to know how to keep snapshots of a resource so that clients can browse through previous versions of the resource.

Solution

Every time a client submits a PUT request to update a resource, before updating the resource, implicitly create a snapshot (a copy resource). In the representation of the updated resource, include a link to the snapshot. Also include a link in the snapshot resource to the updated resource.

When a client submits a DELETE request, delete the resource along with all the snapshots.

Discussion

In essence, this recipe lets you build a simple versioning mechanism ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required