# CORS and caching

Any web page can call the API, and a successful response can be cached for five minutes.

## CORS

Every response carries:

```http
Access-Control-Allow-Origin: *
```

so a web page on any origin can call the API with `fetch` directly.
Preflight requests are answered too, so a browser can send `Content-Type: application/json` or the Connect protocol headers, and the browser may cache the answer for a day (`Access-Control-Max-Age: 86400`).
Nothing is credentialed: the API is keyless, reads no cookies and sets none.

The `RateLimit-*` and `Retry-After` headers are exposed to scripts, so a page can read its remaining allowance.

## Caching

One rule covers every protocol.
A successful `GET` - an HTTP/JSON `GET` or `HEAD`, or a Connect `GET`, including the `301` for a merged Product - carries:

```http
Cache-Control: public, max-age=300
```

Any cache - a browser, a CDN, your own server - may keep it for five minutes and reuse it without asking again.
A cached response can miss a Sync that finished in the last five minutes, so it may show a price DropHawk has since updated.
That is a short window next to how often prices change here: DropHawk Syncs each enabled Listing whose Retailer has not discontinued it at least once a day, and every price is already an observation rather than a live quote.
Caching also keeps you well inside the [rate limit](https://developers.drophawk.net/guides/rate-limits.md).

Every other API response is sent with `Cache-Control: no-store`: any error, and any `POST`, Connect `POST` included.
CORS preflights are the exception: they carry no `Cache-Control`, and `Access-Control-Max-Age: 86400` lets a browser reuse a preflight for a day.
A `404` must not outlive the Product being added, nor a `429` your allowance refilling.

Because a cacheable response can be served to someone else, it carries only `RateLimit-Limit`, not your remaining allowance; see [Rate limits](https://developers.drophawk.net/guides/rate-limits.md#headers).
`HEAD` is answered like `GET`, without a body.
