REST API Basics: Resources, Routes, and CRUD

Core REST API patterns for resource-oriented URLs, nested resources, and standard CRUD request examples.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Resource-oriented routes

Use nouns and predictable URL patterns for resources.

List a collection

Fetch a list of users.

httpANYrestresourcescollections
http
GET /users

Collections should usually be plural nouns. The server returns a list of resources, often with pagination metadata.

Create a resource

Create a new user in the collection.

httpANYrestcreatepost
http
POST /users

POST to a collection is the common create pattern. The server typically returns `201 Created` with the new representation or a location reference.

Fetch a single resource

Read one user by identifier.

httpANYrestreadresource
http
GET /users/{userId}

Single resources usually live at a stable item URL.

Replace a resource

Replace the full representation.

httpANYrestputidempotent
http
PUT /users/{userId}

PUT is typically used when the client sends a full replacement representation and expects idempotent behavior.

Partially update a resource

Modify only selected fields.

httpANYrestpatchupdate
http
PATCH /users/{userId}

PATCH is commonly used for partial updates so clients do not need to send the entire resource.

Delete a resource

Remove one user.

httpANYrestdeleteresource
http
DELETE /users/{userId}

DELETE removes a resource or marks it deleted. Many APIs return `204 No Content` on success.

Nested child resource

Access a child collection under a parent resource.

httpANYrestnestedrelationships
http
GET /users/{userId}/orders

Nested routes are useful when the child is clearly scoped to the parent. Avoid deep nesting when it hurts discoverability.

Subresource details

Read a related settings object.

httpANYrestsubresourcesettings
http
GET /users/{userId}/settings

A subresource can be appropriate when the related object has a stable identity within the parent.

Route shape examples

Preferred route patterns vs less RESTful shapes.

Prefer nouns over verbs

Model the resource, not the action name.

textANYrestnamingroutes
text
Prefer:  POST /invoices
Avoid:   POST /createInvoice

REST routes are usually clearer when they describe resources and let the HTTP method express the action.

Use plural collection names

Keep collection naming consistent.

textANYrestpluralcollections
text
Prefer:  /users
Avoid:   /user

Plural nouns make it easier to distinguish collections from single-resource lookups.

Use stable path identifiers

Put stable IDs in the path.

textANYrestidspaths
text
GET /users/123
GET /orders/ord_456

Stable identifiers make URLs shareable and cache-friendly. Avoid path values that change often.

Represent actions carefully when needed

Use an action subresource only for non-CRUD workflows.

textANYrestactionspayments
text
POST /payments/{paymentId}/refunds

Some domain actions are best modeled as a resource creation under the target resource instead of a verb endpoint like `/refundPayment`.

Recommended next

No recommendations yet.