Chapter 1 · Practice 4 of 4
Use stable, opaque identifiers, and keep secrets out of URLs
From Resources and URLs
Why it matters
Resource ids end up in client databases, logs and bookmarks, so they must never change. Treat them as opaque strings in the contract, even if they are numbers today, so you can change how they are generated later.
- Prefer ids that do not reveal volume or order when that matters, such as UUIDs or prefixed random ids (
ord_8f3k2). - Never put tokens, passwords or personal data in a URL. URLs are written to server logs, proxy logs and browser history. Send credentials in the
Authorizationheader. - Keep URLs free of file extensions (
/orders/7.json); use theAcceptheader for formats.
Sequential integer ids are fine internally, but they make it trivial to enumerate other customers' resources if authorization is ever missing.