stylehub.cloud

API documentation

Caching and CORS

On this page

Every 200 carries an ETag. Send it back and an unchanged manual is a 304 with no body. Public manuals may be cached for a minute; anything a token unlocked is never cached. All three addresses allow any origin for GET.

ETag and 304

The ETag is a fingerprint of the answer. Send it back as If-None-Match, and if nothing changed the answer is 304 Not Modified with the same headers and no body. A 304 still counts as a request; see how calls are counted.

If-None-Match
# First call: keep the ETag it gives you
curl -sS -D headers.txt https://stylehub.cloud/api/v1/manuals/acme/tokens.json -o tokens.json
ETAG=$(grep -i '^etag:' headers.txt | cut -d' ' -f2 | tr -d '\r')

# Later: 304 and an empty body if nothing changed
curl -sS -o tokens.json -w '%{http_code}\n' \
  -H "If-None-Match: $ETAG" \
  https://stylehub.cloud/api/v1/manuals/acme/tokens.json

The PDF has an ETag too, made from everything the document was drawn from, so an unchanged manual is a 304 there as well and no document is drawn or sent. A document out of the server's recent cache is not counted as a render; see the PDF's own allowance.

Cache-Control

public, max-age=60
A public or unlisted manual, read with no token. A proxy or a CDN in between may keep it for a minute.
private, no-store
Any answer to a request that carried a token, a public manual included. It is not the same answer for everyone, so nothing between you and the server may keep it.
no-store
Every error answer. An error carries no ETag and is never kept.

A 200 or 304 also says Vary: Authorization, so a cache that does keep a public answer never serves it to a request that carried a different key.

CORS

  • Access-Control-Allow-Origin: * on every answer, errors included. A page on any site can fetch a public manual directly.
  • Methods: GET and OPTIONS. A preflight answers 204 and may be cached for a day.
  • Request headers allowed: Authorization and If-None-Match.
  • Headers exposed to the page: ETag, the three X-RateLimit headers and Retry-After.
JavaScript
const res = await fetch("https://stylehub.cloud/api/v1/manuals/acme.json");
console.log(res.headers.get("x-ratelimit-remaining"), "requests left this minute");
const manual = await res.json();

A token never belongs in a browser page

Anything a browser can read, a reader can read, and a token reads every manual of its brand. Fetch private manuals from a server, and let the server hand the page what it needs.

Every answer from the three addresses says X-Robots-Tag: noindex. The API is data, and the page is the thing search engines should find. See Search engines and the head of a page for how a manual itself is indexed.

Something the API does that this page does not say? Write to hello@stylehub.cloud with the request and the answer you got.

Caching and CORS - API - Stylehub