General

Best practices

Use GZIP compression

Compression reduces the amount of data being transferred and improves data request speed. Add HTTP headers to enable GZIP compression.

Curl

Code
curl -H "Accept-Encoding: gzip,deflate" \ "https://dataservice.accuweather.com/locations/v1/search?q=san&apikey={API_KEY}"
  • Without compression: 17,695 bytes
  • With compression: 2,958 bytes
  • Size reduction of 83%

TypeScript

TypeScriptCode
const url = "https://dataservice.accuweather.com/locations/v1/search?q=new york&apikey={API_KEY}"; const options = { method: "GET", headers: { "Accept-Encoding": "gzip", }, }; fetch(url, options) .then((response) => { ... });

Randomize refresh rates

Randomize individual device refresh rates so that devices refresh at different clock times. Requesting updates on all devices at consistent times will overload the system.

Use the expires header

Refresh information from the AccuWeather APIs for your device based upon the cache expires time in the response headers. In the example below, refresh on Thursday, August 30th, 2012 at 14:56:34 GMT.

Code
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

Timezone offset changes for daylight saving time

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.

Last modified on