Showing posts with label making. Show all posts
Showing posts with label making. Show all posts

Monday, March 9, 2015

Making PATCH requests from App Engine

PATCH requests allow you to perform partial updates on many of our REST APIs and in most cases can save bandwidth.

If you have ever tried to do a PATCH request on an App Engine application, you probably realized that it is not possible and that the list of HTTP Methods allowed is whitelisted to the following methods only: GET, POST, HEAD, PUT and DELETE. Trying to perform a PATCH request raises the following Exception:

java.net.ProtocolException: PATCH is not one of the supported http methods: [GET, POST, HEAD, PUT, DELETE]

There is a workaround to this. Most of our APIs support the X-HTTP-Method-Override header. This header can be used in a POST request to “fake” other HTTP methods. Simply set the value of the X-HTTP-Method-Override header to the HTTP method you would like to actually perform.

For example, to make a PATCH request to the Google Tasks API to update only the Notes field of a particular task you could use the following HTTP request:

POST /tasks/v1/lists/@default/tasks/TASK_ID HTTP/1.1
Host: www.googleapis.com
X-HTTP-Method-Override: PATCH
Authorization: Bearer
Content-Type: application/json
Content-Length: 31

{“Notes” : “Patch is working!”}

Which would be equivalent to this HTTP Request, which is not supported on App Engine:

PATCH /tasks/v1/lists/@default/tasks/TASK_ID HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer
Content-Type: application/json
Content-Length: 31

{“Notes” : “Patch is working!”}

For instance, in an App Engine Java environment you could construct and execute this request this way:

URL url = new URL("https://www.googleapis.com/tasks/v1/" +     
"lists/@default/tasks/" + TASK_ID);
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.addHeader(new HTTPHeader("X-HTTP-Method-Override", "PATCH"));
request.addHeader(new HTTPHeader("Authorization", "Bearer " +
ACCESS_TOKEN));
request.setPayload("{"Notes" : "Patch is working!"}".getBytes());

URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
HTTPResponse response = fetchService.fetch(request);

This trick can also be used if your application server is behind a firewall, behind a proxy server or in any other environment where HTTP methods other than POST might not be allowed. In that case you could use the X-HTTP-Method-Override header the same way to workaround these limitations.

You may also use our Google APIs Client library for Java or our Google APIs Client library for Python, both of which have support for PATCH requests and use the X-HTTP-Method-Override header when appropriate.


Nicolas Garnier profile | twitter | events

Nicolas joined Google’s Developer Relations in 2008. Since then hes worked on commerce oriented products such as Google Checkout and Google Base. Currently, he is working on Google Apps with a focus on the Google Calendar API, the Google Contacts API, and the Tasks API. Before joining Google, Nicolas worked at Airbus and at the French Space Agency where he built web applications for scientific researchers.

Read more »

Saturday, February 28, 2015

Google Guide Making Searching Even Easier Nancy Blachman

  • Link to Google Guide
  • Using the Google Guide Effectively (FAQs)

WHAT?
"Google Guide is an online interactive tutorial and reference for experienced users, novices, and everyone in between. I developed Google Guide because I wanted more information about Googles capabilties, features, and services than I found on Googles website." - Nancy Blachman

"Google is so easy to use, why take this online tutorial? If you’re like many people, you use only a small number of Google’s services and features. The more you know about how Google works, its features and capabilities, the better it can serve your needs (Source)."

JUICE?
I found this useful Google guide when I was snooping around in Jane Knights super blog. When you first look at this Google Guide, you might be thinking this is just a simple HTML page with a few plain non-attractive graphics. Though, simplicity is one of Googles secret weapons and this is what I like about this guide, too. Anyway, do we really need any Superman or Batman animations to engage our minds to explore it? Where am I going? Wake up! In short, this guide can help us improve our skills and speed to find the learning juice we are Googling for (if indexed by Google!). The guide can for example be explored according to three (3) levels:

  • Novices - Explains how to write a query that will help you find just what you want.
  • Experts - (or Experienced users) Appear to describe basic concepts, but if you read carefully, you’ll discover helpful insights into how Google works and how to use it more effectively.
  • Teens - Provides a lot of different types of sample queries and exercises (Get straight to the point, I am a teen!).

In addition, you can easily jump to different sections (e.g. Query Input and Search Tools). Yes, it even gives you tips on how to develop a search-friendly Website (or improve your PageRank). Also, if you have time (or no time!), check out the Cheat Sheet (2-page quick reference) and Calculator Cheat Sheet (Solve mathematical problems with Googles built-in calculator function!) . Cool stuff to learn! Yeah, I really like the fact that the guide looks like a blog (Is it a blog?). It gives you a more relaxed and informal learning touch to it!

Although, it also has a Google Guide search box, it does not appear on the guides home page, meaning it will only appear on pages within the guide (upper-left corner!). I suppose I would prefer that the search box is also accessible from the homepage. Anyway, this is a small matter which takes a few seconds to change, if they really want to. What is important, is that this guide can assist us in improving our Googling ability, so that we can find the juice we are looking for :)

Read more »