July 19th, 2011 | Published in Google Code
Over a year ago, we launched support for partial response and partial update for a number of APIs based on the Google Data Protocol. That launch was a part of our continuous effort to make the web faster. It was well received by our developer community as it significantly reduced network, memory, and CPU resources needed to work with certain Google APIs.
Today, we are adding support for partial response and an improved version of partial update, called patch, to a number of newer APIs such as Buzz, URL Shortener, Tasks and many others. In fact, all APIs available in the Google APIs Discovery Service and the APIs Explorer now support this feature.
To learn how to use partial response and partial update with a Google API, you can see the “Performance Tips” page in the documentation of the Tasks and Buzz APIs. We’ll roll out this page for all of the supported APIs over the next few months, but you can already use the algorithms with all of them today.
The partial response algorithm is identical to what was provided by the Google Data Protocol. By supplying a
fieldsquery parameter to any API call that returns data, you can request specific fields. Here is an example request that returns only titles and timestamps of a user’s public Buzz activities:
https://firstname.lastname@example.org/@public?alt=json&pp=1&fields=items(title,updated)Given that the full response is around 53KB and the partial response is only 3KB, the data sent to the client is reduced by almost 95%!
While the partial response algorithm is unchanged, the partial update algorithm has changed significantly compared to what was provided by Google Data Protocol. We’ve received feedback that the old algorithm was too complicated and hard to use, which prompted us to design something much simpler. The basics remain the same: you can use the HTTP
PATCHverb in supported API methods to send partial updates to Google servers. However, the mechanics are different. Adding and modifying data uses the same 'merge' semantics as before. But deleting is simplified; just set a field to 'null'. Of course, the devil is in the details, so please check out the documentation for the nitty gritty.
You can try out both partial response and patch algorithms in the APIs Explorer. For partial responses, the fields parameter is available for most methods. In addition, the partial update methods are denoted by
.patchin the method name. You can try both the fields parameter and the patch method on the “tasklist” resource in the APIs explorer.
If you are using Java or Python client libraries to access Google APIs, you can already ask for partial responses and send patch requests in the code. We are adding partial support to the rest of the Google APIs client libraries over time.
As our APIs get more and more use from devices with limited resources, taking advantage of performance optimizations such as partial response and patch is crucial for making your applications faster and more efficient. By using these features in your applications, you are joining us in our effort to make the web faster. For this, we thank you! Let us know of any issues and feature requests by posting to the developer forums of your favorite APIs or by leaving a comment on this post. Happy hacking!
Anton Lopyrev is an Associate Product Manager for Google APIs Infrastructure. He is a computer graphics enthusiast who is also passionate about product design.
Sven Mawson is a Software Engineer working on Google’s API Infrastructure. He believes well-designed, beautiful APIs need not sacrifice performance.
Posted by Scott Knaster, Editor