O'Reilly logo

RESTful Web Services Cookbook 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

11.8. How to Refine Resources for Partial Updates

At some point, you are likely to encounter a situation where you need to partially update an existing resource. This may happen if the resource is large and/or the update you want to make is small. In these cases, it may seem wasteful to submit a GET request to get the entire representation, make the small change, and submit a PUT request with the entire representation back to the server to update the resource. When you are confronted with such a situation, one of the first solutions to consider is to refine the resource in question in a way that removes the need for partial updates in the first place. See Recipe 11.9 for an alternative.

Problem

You want to know how to refine resources so that clients can partially update resources.

Solution

Design a new resource that encapsulates the parts of the resource that a client can modify. Let clients use PUT to update that resource, in effect partially updating the original resource.

Discussion

The key advantage of this solution is that it gives clients the ability to update subsets of the original resource by using the HTTP method PUT. It also has the added bonus of making otherwise previously hidden resources accessible via their own URIs to clients.

For example, consider the following representation of a customer resource:

# Request GET /customers/1 HTTP/1.1 Host: www.example.org # Response HTTP/1.1 200 OK Content-Type: application/xml;charset=UTF-8 Last-Modified: Thu, 05 Nov 2009 01:54:19 GMT ...

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