{"_id":"566b57f068eba90d009cac72","user":"5531215e29603d2300011341","__v":3,"project":"55312174c68f493900aebb3f","category":{"_id":"566b59110506f40d0034f148","__v":5,"pages":["566b5afcec4a320d00a8ca76","566b63213d25d00d0066b00a","56a47942e5e9190d00ad6200","56a480315fb2530d00421b75","56a489ae9093960d00f9ab31"],"project":"55312174c68f493900aebb3f","version":"55312174c68f493900aebb42","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2015-12-11T23:15:29.864Z","from_sync":false,"order":2,"slug":"extra-parameters","title":"Extra Parameters"},"version":{"_id":"55312174c68f493900aebb42","project":"55312174c68f493900aebb3f","__v":10,"createdAt":"2015-04-17T15:06:28.598Z","releaseDate":"2015-04-17T15:06:28.598Z","categories":["55312175c68f493900aebb43","566b431d03b4b20d00d02c3a","566b58f212bc0517005d3068","566b59110506f40d0034f148","566b7cc94d1a4d0d00801c00","566b82d130cdb417008d217d","566b855b4d1a4d0d00801c04","566b856f03870a0d008ee7a7","566c42d2f0a5dc0d009acbab","566c443d85dc790d0062c134"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.7.0","version":"0.7"},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-11T23:10:40.680Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"From the  article on Etags:\n\n> An ETag [\"Entity Tag\"] is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource content at that URL ever changes, a new and different ETag is assigned. Used in this manner ETags are similar to fingerprints, and they can be quickly compared to determine if two versions of a resource are the same or not.\n> -- [Wikipedia](http://en.wikipedia.org/wiki/HTTP_ETag)\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Store the latest API response\"\n}\n[/block]\nEach time you make a request to the Open Exchange Rates API, the HTTP response headers will include an `ETag` and a `Date`. \n\nThe `Etag` is a unique identifier for the data returned in the response, and the `Date` is the time at which the data was last modified. \n\nExample:\n\n```\nDate: Thu, 20 Dec 2012 14:48:28 GMT\nETag: \"4e6acdd9fea30c21d9bdf1925afbf846\"\n```\n\nAfter receiving your API response, cache the **entire** response somewhere (e.g. to a file, database or in memory), along with the values for the `ETag` and `Date` headers.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Add the \\\"If-None-Match\\\" header\"\n}\n[/block]\nNext time you make a request to the same API URL, add the `If-None-Match` header, with the value set to the `ETag` you grabbed from the previous request, wrapped in double quotation '\"' marks. \n\nYou also need to send an `If-Modified-Since` header, which will be the `Date` value from the last successful request. \n\nUsing the example above, your two request headers would look like this:\n\n```\nIf-None-Match: \"4e6acdd9fea30c21d9bdf1925afbf846\"\nIf-Modified-Since: Thu, 20 Dec 2012 14:48:28 GMT\n```\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. If not modified, use cached data\"\n}\n[/block]\nIf the data have not been updated since your last request, the response status code will be **304 – Not Modified**, and _no data will be returned_. \n\nYou can now safely use the cached API response from your previous successful request.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. If updated, cache the new response\"\n}\n[/block]\nIf the rates **have changed** since your last request, the latest data will returned as usual, along with new `ETag` and `Date`` headers. \n\nRepeat Step 1.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Please note: Although ETags help reduce bandwidth for your users, all API requests still count towards your monthly request allowance – even if the data has not changed since your last request.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Further Examples\"\n}\n[/block]\n  * [This post](https://developers.facebook.com/blog/post/627/) on the Facebook Developers blog contains a solid run-down of ETags.","excerpt":"ETags (“If-None-Match”) provide a simple method of saving bandwidth, by checking whether the rates have been updated since your last request. \n\nIf the data have not changed since your previous request, you can fallback to a cached copy, and your API response will be under 0.2kb (instead of the standard 2–4kb response). If the rates have changed, you'll receive the latest data as usual.\n\nIt's easier than it sounds - here's a step-by-step guide to prove it!","slug":"etags","type":"basic","title":"ETags / Cache Control"}

ETags / Cache Control

ETags (“If-None-Match”) provide a simple method of saving bandwidth, by checking whether the rates have been updated since your last request. If the data have not changed since your previous request, you can fallback to a cached copy, and your API response will be under 0.2kb (instead of the standard 2–4kb response). If the rates have changed, you'll receive the latest data as usual. It's easier than it sounds - here's a step-by-step guide to prove it!

From the article on Etags: > An ETag ["Entity Tag"] is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource content at that URL ever changes, a new and different ETag is assigned. Used in this manner ETags are similar to fingerprints, and they can be quickly compared to determine if two versions of a resource are the same or not. > -- [Wikipedia](http://en.wikipedia.org/wiki/HTTP_ETag) [block:api-header] { "type": "basic", "title": "1. Store the latest API response" } [/block] Each time you make a request to the Open Exchange Rates API, the HTTP response headers will include an `ETag` and a `Date`. The `Etag` is a unique identifier for the data returned in the response, and the `Date` is the time at which the data was last modified. Example: ``` Date: Thu, 20 Dec 2012 14:48:28 GMT ETag: "4e6acdd9fea30c21d9bdf1925afbf846" ``` After receiving your API response, cache the **entire** response somewhere (e.g. to a file, database or in memory), along with the values for the `ETag` and `Date` headers. [block:api-header] { "type": "basic", "title": "2. Add the \"If-None-Match\" header" } [/block] Next time you make a request to the same API URL, add the `If-None-Match` header, with the value set to the `ETag` you grabbed from the previous request, wrapped in double quotation '"' marks. You also need to send an `If-Modified-Since` header, which will be the `Date` value from the last successful request. Using the example above, your two request headers would look like this: ``` If-None-Match: "4e6acdd9fea30c21d9bdf1925afbf846" If-Modified-Since: Thu, 20 Dec 2012 14:48:28 GMT ``` [block:api-header] { "type": "basic", "title": "3. If not modified, use cached data" } [/block] If the data have not been updated since your last request, the response status code will be **304 – Not Modified**, and _no data will be returned_. You can now safely use the cached API response from your previous successful request. [block:api-header] { "type": "basic", "title": "4. If updated, cache the new response" } [/block] If the rates **have changed** since your last request, the latest data will returned as usual, along with new `ETag` and `Date`` headers. Repeat Step 1. [block:callout] { "type": "info", "body": "Please note: Although ETags help reduce bandwidth for your users, all API requests still count towards your monthly request allowance – even if the data has not changed since your last request." } [/block] [block:api-header] { "type": "basic", "title": "Further Examples" } [/block] * [This post](https://developers.facebook.com/blog/post/627/) on the Facebook Developers blog contains a solid run-down of ETags.