Kazi Rahamatullah
Kazi Rahamatullah
AboutProjectsBlogContact
UsesBooks
ResumeView CV
Kazi Rahamatullah

© Copyright 2026 Kazi Rahamatullah

AboutProjectsBlogBooksUses
Twitter/XGitHubProduct HuntCodeSandbox
Back to Blog
System DesignAPI DesignRESTBackendIntegration

System Design: API Design

REST API contracts — endpoint naming, versioning, request-response structure, and error design. Interactive explorer comparing v1 vs v2 payloads.

Jul 8, 20262 min read

Introduction

Endpoint naming, versioning, and request-response structure are your communication contract. Poor API design means broken integrations, fragile mobile clients, and expensive version migrations.

Quote

A poor API means broken integration.

This guide covers practical REST design with an interactive contract explorer — toggle API versions and compare payloads side by side.

← Back to System Design overview

Design principles

Resource-oriented URLs

Use nouns, not verbs:

plaintext
GET    /api/v2/users
POST   /api/v2/orders
GET    /api/v2/orders/{id}
PATCH  /api/v2/orders/{id}

Avoid /getUser, /createOrder — HTTP methods already express the action.

Versioning

StrategyProsCons
URL path (/v2/)Explicit, easy to routeURL churn
Header (Accept-Version)Clean URLsHarder to test in browser
Query paramQuick experimentsEasy to forget

Tip

Version when you break compatibility — field renames, pagination model changes, auth changes. Do not version for every small addition; prefer additive changes.

Request and response shape

Consistent envelopes help clients:

json
{
  "data": {},
  "error": null,
  "meta": { "requestId": "req_abc" }
}

Errors should be machine-readable:

json
{
  "error": {
    "code": "ORDER_INVALID_ITEMS",
    "message": "Line items cannot be empty",
    "field": "lineItems"
  }
}

Interactive contract explorer

Switch between v1 and v2 to see how naming and pagination evolve without breaking the mental model.

API Contract Explorer

Compare versioning and request-response shape for the same operations.

Request

Query: ?cursor=abc&limit=20

Response

{
  "data": [{ "id": "usr_1", "fullName": "Asha" }],
  "nextCursor": "def"
}

Pagination patterns

Offset (?page=2&limit=20) — simple, but slow on large tables.

Cursor (?cursor=abc&limit=20) — stable for feeds and real-time inserts; preferred at scale.

Performance

Cursor pagination avoids OFFSET 100000 scans. Return nextCursor in the response and document sort order explicitly.

Idempotency and safety

POST creates resources. For payments and orders, accept an Idempotency-Key header so retries do not double-charge.

http
POST /api/v2/orders
Idempotency-Key: 7f3c9a2e-...

Interview Answer

API design interview flow: define resources from use cases → pick REST verbs → show one happy-path request/response → define error codes → explain versioning strategy → mention auth (JWT, API keys) and rate limits if scale is high.

Back to index


Share this article

XLinkedInFacebook
Kazi Rahamatullah

Written by

Kazi Rahamatullah

FullStack Developer

X / TwitterGitHubLinkedIn

Subscribe to my newsletter

Stay up to date and get notified when I share new contents.

No spam ever, unsubscribe anytime