Google App Engine recently announced version 1.5.1 of its App Engine SDK. One of the features that interests me is that of the new header added in every client request.
The official announcement from Google is given below:
App Engine will now include a header with every client request that represents a best-effort attempt to identify the country from which the request originated. This header X-AppEngine-country can allow you to customize content based on the origin of the user.
Location is a big thing in most applications. Typically you can classify Location Based Applications into two types:
- One that requires coarse grained information. What this means is that it is enough to know if the user is from a particular city or country. There is no need to know the exact co-ordinates.
- The other type requires access to accurate location information and this typically means getting information about the latitude and longitude. The lat, lon are then used to further fine tune the results or actions.
The X-AppEngine-country is fantastic for applications that need coarse grained location information and would definitely help to avoid some network calls.
To test out, I wrote a simple Google App Engine Java project which has a single page (index.jsp) that simply sniffs the value of this header and prints it out. I was more interested in seeing what it returns. Here is the snippet of code that prints a greeting and the country from where you are accessing the page:
<h2>Hello My Friend from <%=request.getHeader("X-AppEngine-country") %></h2>
Since I live in India, it does a good job and prints out the following (as shown in the screenshot below):
You can try it too.
While this is a good start, here are some points:
- The country code that it provides are standard country abbreviations. Here is a list. If your application does not deal directly with the country code and requires some other value (e.g. full country name) — you might still have to do a lookup.
- Several public APIs that require a coarse grained location might still not work with just the country code given here. So some additional translation might be due.
- I still think this is a great start. And my suggestion to the Google Team if they haven’t already implemented it is to implement the a Header that I shall take the liberty of calling X-AppEngine-city.
Read more Episodes on App Engine Services
- Writing Google Talk Bots with App Engine
- Write your first Google Chrome Extension, powered by App Engine
- Scheduling Background Tasks in App Engine: Learn about the Cron Scheduler in App Engine
- Asynchronous Processing in App Engine: Learn about tasks / queues in App Engine
- Handling Email in App Engine Applications: Sending and Receiving incoming Email in your App Engine applications
- Blobstore Tutorial : Use the App Engine Blobstore service to store data in GB
- Datastore Tutorial : Basic database programming in App Engine
- Captcha Tutorial: How to integrate a Captcha in your App Engine application
- Location Services: Learn how to detect Location (Latitude & Longitude) in your App Engine Application. Part 1 and Part 2.
- Memcache: Learn how to use the cache to speed up your App Engine applications
- Networking: Learn how to make calls to external Web Services using URLFetch service in App Engine.
- Download the eBook: All the episodes packaged for you in a free eBook. Enjoy and thanks for downloading.