O'Reilly logo

RESTful Java Patterns and Best Practices by Bhakti Mehta

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

HTTP PATCH and partial updates

A common problem for API developers is to implement partial updates. This can happen when the client sends a request that must change just one part of a resource's state. For example, imagine that there is a JSON representation of your Coffee resource that looks like the following code snippet:

{
 "id": 1,
 "name": "Mocha"
 "size": "Small",
 "type": "Latte",
 "status":"PROCESSING"
}

Once the order is completed, the status needs to be changed from "PROCESSING" to "COMPLETED".

In an RPC-style API, this could be handled by adding a method as follows:

GET myservice/rpc/coffeeOrder/setOrderStatus?completed=true&coffeeId=1234

In the REST case using the PUT method, all the data like this needs to be sent, which will waste bandwidth ...

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