Build with DEX · 32 reference entries

API reference

Design understandable HTTP contracts with validation, access checks, bounded work, useful errors and deliberate caching.

API examples need the application's real session, validation and storage layers. These notes explain the design decisions and checks; adding them to the reference library does not enable a service or certify a live endpoint.

All reference topics · Reviewed source links

Entry index

Choose an entry or use Find on page to look for a term. Each number identifies an educational reference; production checks need their own recorded result.

HTTP contracts

WEB-API-001

Resource names and methods

Choose stable resource URLs and use methods according to their semantics. Document the allowed operations and response shapes for each resource.

Example and documentation
GET /example-api/lessons
GET /example-api/lessons/42
POST /example-api/lessons

Documentation: API and security documentation

Link to WEB-API-001 · Back to entry index

WEB-API-002

Safe read operations

GET and HEAD should retrieve information without performing a requested state change. A crawler or retry may repeat them.

Example and documentation
GET /example-api/lessons/42 → read a lesson
POST /example-api/lessons → create a lesson

Documentation: API and security documentation

Link to WEB-API-002 · Back to entry index

WEB-API-003

Idempotent updates

An idempotent operation has the same intended effect when repeated. It can still return different response details as the resource state changes.

Example and documentation
PUT /example-api/preferences/theme
Body: {"theme":"system"}

Documentation: API and security documentation

Link to WEB-API-003 · Back to entry index

WEB-API-004

Replay-safe creation

A create operation may need an application idempotency contract. Store a key and the result atomically so a retry cannot create a duplicate.

Example and documentation
Contract example: a client supplies one request key for a create attempt; the server returns the stored result for a matching replay.

Documentation: API and security documentation

Link to WEB-API-004 · Back to entry index

WEB-API-005

Meaningful response statuses

Choose a status that represents the outcome. Clients need to distinguish an invalid request, missing resource and temporary service failure.

Example and documentation
200: successful read
201: resource created
400: invalid request
404: missing resource
503: temporary unavailability

Documentation: API and security documentation

Link to WEB-API-005 · Back to entry index

WEB-API-007

Content types

Validate the incoming format and declare the outgoing one. Do not interpret an arbitrary body as JSON without checking the contract.

Example and documentation
Request: Content-Type: application/json
Response: Content-Type: application/json; charset=utf-8

Documentation: API and security documentation

Link to WEB-API-007 · Back to entry index

WEB-API-008

Consistent problem details

Return a predictable error structure with a useful title and status. Problem Details provides a standard vocabulary for API errors.

Example and documentation
Content-Type: application/problem+json
{"type":"about:blank","title":"Invalid request","status":400,"detail":"The page size must be between 1 and 100."}

Documentation: API and security documentation

Link to WEB-API-008 · Back to entry index

Validation and access

WEB-API-009

Server-side validation

Validate the type, range and permitted values of every accepted field. Browser checks improve the interface but do not enforce an API contract.

Example and documentation
const limit = Number(url.searchParams.get("limit") ?? "25");
if (!Number.isInteger(limit) || limit < 1 || limit > 100) return invalidRequest();

Documentation: API and security documentation

Link to WEB-API-009 · Back to entry index

WEB-API-010

Bounded request bodies

Limit body size before expensive parsing and check the actual bytes received. A Content-Length value alone is not a complete enforcement mechanism.

Example and documentation
Reject a body that exceeds the endpoint's documented limit with an appropriate 413 response.

Documentation: API and security documentation

Link to WEB-API-010 · Back to entry index

WEB-API-011

Authentication and authorisation

Verify who is calling, then check permission for the specific operation. A valid session does not grant access to every resource.

Example and documentation
Request → verify session → check allowed action → load authorised resource → return permitted fields

Documentation: API and security documentation

Link to WEB-API-011 · Back to entry index

WEB-API-013

Explicit response fields

Build public and member responses from an allowlist of intended fields. A new internal database column must not silently become an API field.

Example and documentation
const response = { id: record.id, title: record.title, status: record.status };

Documentation: API and security documentation

Link to WEB-API-013 · Back to entry index

WEB-API-014

Session cookies

Use secure, HttpOnly cookies with an appropriate SameSite policy. Keep session scope and expiry aligned with the authentication design.

Example and documentation
Set-Cookie: __Host-session=opaque-value; Path=/; Secure; HttpOnly; SameSite=Lax

Documentation: API and security documentation

Link to WEB-API-014 · Back to entry index

WEB-API-016

CSRF protection

For cookie-authenticated state changes, apply the application's CSRF protections and origin checks. Do not assume a JSON body or CORS policy solves every case.

Example and documentation
Validate the request origin and the application's anti-CSRF token before changing account state.

Documentation: API and security documentation

Link to WEB-API-016 · Back to entry index

WEB-API-017

Secret boundaries

Keep private keys and privileged credentials in server-side secret storage. Browser code, public URLs and response bodies are public delivery surfaces.

Example and documentation
Browser → authenticated application endpoint
Server → upstream service using a protected server credential

Documentation: API and security documentation

Link to WEB-API-017 · Back to entry index

WEB-API-018

Safe outbound destinations

An endpoint that fetches a user-supplied URL needs a deliberate destination policy. Validate redirects and prevent access to internal or privileged network targets.

Example and documentation
Accept only the intended scheme and approved destinations; re-check each permitted redirect before following it.

Documentation: API and security documentation

Link to WEB-API-018 · Back to entry index

Load and reliability

WEB-API-020

Bounded retries

Retry only failures and operations that are safe to repeat. Use a retry limit, delay and jitter rather than immediate unlimited repetition.

Example and documentation
Retry policy: at most 2 additional safe-read attempts; honour Retry-After; stop after the overall deadline.

Documentation: API and security documentation

Link to WEB-API-020 · Back to entry index

WEB-API-021

Timeout and cancellation

Give upstream work a time budget and cancel obsolete work where supported. Map an upstream timeout to a clear response and recovery path.

Example and documentation
const response = await fetch(upstreamUrl, { signal: AbortSignal.timeout(8000) });

Documentation: API and security documentation

Link to WEB-API-021 · Back to entry index

WEB-API-022

Bounded pagination

Enforce a maximum page size and return enough information to continue. A client-provided limit should never permit an unbounded query.

Example and documentation
{"items":[{"id":"42","title":"HTML"}],"nextCursor":"opaque-cursor"}

Documentation: API and security documentation

Link to WEB-API-022 · Back to entry index

WEB-API-024

Query parameter allowlists

Accept only recognised filter and sort values. Bind data values and map approved sort names to fixed SQL fragments.

Example and documentation
const sorts = { newest: "created_at DESC, id DESC", title: "title ASC, id ASC" };
const order = sorts[requestedSort] ?? sorts.newest;

Documentation: API and security documentation

Link to WEB-API-024 · Back to entry index

Caching and evidence

WEB-API-025

Cache policy by response

Choose a policy based on whether the response is public, user-specific or sensitive. Ensure shared caches cannot serve one person's data to another.

Example and documentation
For a sensitive account response:
Cache-Control: private, no-store

Documentation: API and security documentation

Link to WEB-API-025 · Back to entry index

WEB-API-026

Validators and conditional reads

Use a validator such as ETag to let clients ask whether a representation has changed. Return a body only when required by the request outcome.

Example and documentation
Response: ETag: "lesson-v3"
Next request: If-None-Match: "lesson-v3"
Unchanged response: 304 Not Modified

Documentation: API and security documentation

Link to WEB-API-026 · Back to entry index

WEB-API-027

Varying representations

When response content depends on a request header, declare the relevant variation for caches. Avoid uncontrolled variation that destroys useful reuse.

Example and documentation
Vary: Accept-Encoding

For dynamic origin-specific CORS responses, also consider Origin.

Documentation: API and security documentation

Link to WEB-API-027 · Back to entry index

WEB-API-028

Request correlation

Assign a request identifier and connect it to server diagnostics. Log necessary facts while excluding credentials and sensitive request content.

Example and documentation
Diagnostic fields: request ID, route, status, elapsed time and a non-sensitive error category.

Documentation: API and security documentation

Link to WEB-API-028 · Back to entry index

WEB-API-029

Useful errors without internal leaks

Give clients an actionable message while keeping stack traces, SQL text and secret configuration out of public error bodies.

Example and documentation
{"error":{"code":"TEMPORARILY_UNAVAILABLE","message":"This request could not finish. Try again shortly."}}

Documentation: API and security documentation

Link to WEB-API-029 · Back to entry index

WEB-API-030

Webhook verification and replay handling

Verify the sender using its documented signature scheme, then handle repeated deliveries idempotently. Preserve the raw body when the signature contract requires it.

Example and documentation
Receive raw body → verify signature and timestamp → check delivery ID → apply the event once.

Documentation: API and security documentation

Link to WEB-API-030 · Back to entry index

WEB-API-031

Compatibility and deprecation

Document contract changes and keep existing consumers working through an intentional migration. Test old and new response shapes during a supported transition.

Example and documentation
Change record: affected endpoint, compatibility period, replacement field and migration instructions.

Documentation: API and security documentation

Link to WEB-API-031 · Back to entry index

WEB-API-032

API acceptance evidence

Test normal requests and realistic failure cases against the implemented endpoint. An example in documentation is not proof of live behaviour.

Example and documentation
Record: unauthenticated, wrong-owner, invalid-input, oversized-body, rate-limit, success and upstream-failure outcomes.

Documentation: API and security documentation

Link to WEB-API-032 · Back to entry index

Continue learning

Reviewed . Send a correction through contact and corrections, including the entry number and supporting documentation.

How it works · DEX

Find, save and shop

Explore offers, save a shortlist and buy with the retailer.

More help and things to check

Confirm current prices and offer terms with the retailer. Device saves start in this browser. Account sync is optional.

Shopping tools & alerts
Household calendarYour For You findsWatch a priceAdd to Home Screen

Choose your deal alerts

Get selected updates about offers you save. You choose whether to enable notifications on this device.