Skip to main content
Web DevAPIs & NetworkingDiagramBeginner

REST API

KO: REST API·EN: REST API·JA: REST API·Representational State Transfer

A stateless web API architectural style that identifies resources via URIs and manipulates them using standard HTTP methods and status codes

Table of Contents

Structure Diagram

REST API Stateless Request-Response Cycle
REST / HTTP1. Client Re…2. HTTP Meth…3. Stateless…4. Status + …
2/42. HTTP Method
GET · POST · PATCH · DELETE
Quick Answer

What is REST API?

A stateless web API architectural style that identifies resources via URIs and manipulates them using standard HTTP methods and status codes. It is a core concept in APIs & Networking within Web Dev.

Core Principles

REST (Representational State Transfer) is an architectural style defined by Roy Fielding that aligns API design with the native semantics of HTTP. Domain entities are modeled as resources addressed by noun-based URIs (such as /users/42/orders), while actions map to standard HTTP verbs—GET (read), POST (create), PUT/PATCH (update), and DELETE (remove).

Because REST is stateless, every request carries all information required to authenticate and execute it. Servers do not need sticky sessions in memory, which makes horizontal scaling behind load balancers and standard HTTP caching (Cache-Control, ETag) effortless.

Practical Takeaways

  • Use plural nouns in URIs and honest HTTP status codes: Favor GET /orders over /getOrders, and return accurate codes (201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 429 Too Many Requests) so clients and proxies behave predictably.
  • Design for idempotency: GET, PUT, and DELETE should leave the system in the same state even when retried. For non-idempotent POST operations like payments, require an Idempotency-Key header to prevent duplicate charges.
  • Plan pagination and versioning early: Introduce cursor-based pagination (?cursor=...&limit=20) and a clear versioning policy (/v1/...) upfront so breaking schema changes never brick older mobile clients.

Notable Examples

  • Stripe, GitHub, and Twilio APIs: Industry benchmarks for clean resource modeling, consistent error payloads, and idempotent mutations.
  • Unified Web & Mobile Backends: Serving JSON representations to web SPAs, iOS, and Android apps from a single HTTP surface.
  • Edge-cached public endpoints: Pairing GET REST endpoints with CDN Cache-Control headers to serve millions of reads without hitting origin databases.

Practical Code Snippet

Copy and drop straight into your project
terms-route.tsTypeScript
// GET /api/terms?domain=dev&limit=20export async function GET(request: Request) {  const { searchParams } = new URL(request.url);  const domain = searchParams.get("domain");   const terms = await db.terms.findMany({    where: domain ? { domain } : undefined,    take: Number(searchParams.get("limit") ?? 20),  });   return Response.json({ data: terms }, { status: 200 });}