Authentication
Use bearer tokens, API keys, or signed requests so only approved clients can access data.
REST API Intermediate
Intermediate REST work is where an endpoint becomes useful to frontend teams, internal tools, dashboards, and partner integrations. This is where auth, pagination, filtering, and validation matter.
Use bearer tokens, API keys, or signed requests so only approved clients can access data.
Split large lists into pages or cursor windows so responses stay fast and predictable.
Allow clients to ask for exactly the records they need instead of returning everything.
Reject missing or malformed input before it reaches the database.
Keep `/v1` or header-based versions for breaking changes.
Use ETag, Cache-Control, or CDN caching on safe GET endpoints.
Protect side-effecting retries with idempotency keys so duplicate charges, orders, or events are not created.
Use consistent error payloads instead of bespoke error shapes per endpoint.
{
"success": true,
"data": [
{ "id": 1, "title": "Campaign A", "status": "active" },
{ "id": 2, "title": "Campaign B", "status": "paused" }
],
"pagination": {
"page": 1,
"limit": 2,
"total": 18,
"pages": 9
}
}
{
"type": "https://example.com/problems/validation-error",
"title": "Validation failed",
"status": 400,
"detail": "name is required",
"instance": "/v1/items"
}
This is the point where REST meets the website UI. The browser calls the endpoint, gets JSON, and re-renders cards, tables, charts, or forms.
async function loadCampaigns(page = 1) {
const response = await fetch(`/pages/api.php?table=blogs&limit=5&page=${page}&key=YOUR_KEY`, {
headers: {
"Accept": "application/json",
"X-API-Version": "1.0"
}
});
if (!response.ok) {
throw new Error(`Request failed with ${response.status}`);
}
const data = await response.json();
renderCampaigns(data);
}