Store ranking in JSON format detail view, caching
Introduction
We are happy to announce extension of our JSON formatted page hodnoceni-obchodu reffered here. We discovered that important data are missing, such as scores, average scores, etc.
To ensure backward compatibility, we added an optional header that will modify the display of details. Please compare the following request to the request mentioned in the previous post and change it accordingly. Please see that the former array has moved to an object called ratings.
Example
JavaScript – try e. g. on Classic: https://classic.shoptet.cz/
const request = await fetch('/cache/hodnoceni-obchodu/', {headers: {'Content-Type': 'application/json', 'X-Store-Rating-Details': 'true'}}); request.json().then(response => console.log(response));
Please note that this might not work in older versions of the Safari browser: they do not support
awaitdirectly in the browser console.
Curl
curl -H "content-type: application/json" -H "X-Store-Rating-Details: true" https://classic.shoptet.cz/hodnoceni-obchodu/
Caching
You’re encouraged to use cache as much as possible. There is a caveat, though. You get the first cached request, and headers don’t invoke a new caching. So you have to use any query parameter to make the JSON version cached and work with it.
Example
In the following example, see jsonFormat query in the URL.
const request = await fetch('/cache/hodnoceni-obchodu/?jsonFormat', {headers: {'Content-Type': 'application/json', 'X-Store-Rating-Details': 'true'}}); request.json().then(response => console.log(response));