Best Practices
- Use GZIP compression
- Randomize refresh rates
- Refresh data using the expires header from the response
- IMPORTANT: Time zone offset changes due to Daylight Saving time
- MinuteCast™ Caching
Use GZIP compression
- Reduces the size of data being transmitted to the device
- Increases the speed of the data requests
- GZIP compression is easily turned on by adding HTTP headers
Curl Example:
curl -H "Accept-Encoding: gzip,deflate" "http://api.accuweather.com/locations/v1/search?q=san&apikey={your key}" |
- Without compression, size=17695 bytes
- With compression, size=2958 bytes
Java Example:
HttpUriRequest=new HttpGet(http://api.accuweather.com/locations/v1/search?q=san&apikey={your key}); request.addHeader("Accept-Encoding", "gzip"); // ... httpClient.execute(request); |
Randomize refresh rates
-
Add some type of randomization to the individual device refresh time so that all devices don't refresh at the same clock time.
-
For example, do not request updates on all devices at :00 and :30 past the hour
Use Expires header
- Refresh information from the AccuWeather API for your device based upon the cache expires time in the response headers
Example:
Response Headers Cache-Control: public Content-Encoding: gzip Content-Type: application/json; charset=utf-8 Date: Wed, 29 Aug 2012 14:55:33 GMT Expires: Thu, 30 Aug 2012 14:56:34 GMT Server: Microsoft-IIS/7.5 Server: Microsoft-IIS/7.0 Transfer-Encoding: chunked Vary: Accept-Encoding X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET |
- In this example, do not refresh until: Thu, 30 Aug 2012 14:56:34 GMT
Timezone Offset Changes for Daylight Savings
- If you intend to use the GMTOffset from the Location Api response to calculate times local to the location, you MUST be careful to observe the NextOffsetChange property. The offset will change on the date and time specified.
- Using the expires header as described above will ensure that you have the most current GMTOffset for the location.
MinuteCast™ Caching
- AccuWeather is working with global partners to expand MinuteCast™ worldwide. However, for locations where it is not currently supported, an HTTP 400 response is returned.
- To reduce data consumption and prolong battery life in some devices, we recommend that developers cache MinuteCast™ HTTP 400 responses for 72 hours to prevent subsequent requests from returning the error.