After this lesson, you will be able to: Design REST endpoints with naming conventions, versioning, pagination, filtering, sorting, and nested resources.
Design is what separates pleasant APIs from painful ones. Good design is consistent + predictable; clients can guess the next endpoint correctly.
Resources are NOUNS, plural: `/users`, `/posts`, `/orders`. Operations are HTTP VERBS, not in the URL: `POST /users`, not `POST /createUser`. IDs are path segments: `/users/42/posts/7`. Use kebab-case in URLs: `/posted-sessions`, not `/postedSessions`. Lowercase everywhere; HTTPS everywhere.
Memorize these shapes.
GET /users → list usersGET /users/42 → get one userPOST /users → create a userPUT /users/42 → replace user 42 fullyPATCH /users/42 → partial updateDELETE /users/42 → delete// Nested resourcesGET /users/42/posts → posts by user 42POST /users/42/posts → create post for user 42GET /users/42/posts/7 → user 42's post 7// Sub-actions (when REST verbs don't fit cleanly)POST /users/42/activate → trigger activation (use sparingly)POST /orders/99/refund → trigger refund
Two strategies. Pick one.
// Offset-based (simple; slow on big pages)GET /posts?page=3&limit=20GET /posts?offset=40&limit=20// Response{"data": [ ... ],"page": 3,"limit": 20,"total": 1234,"totalPages": 62}// Cursor-based (preferred for large datasets + real-time feeds)GET /posts?cursor=eyJpZCI6MTIzfQ&limit=20// Response{"data": [ ... ],"nextCursor": "eyJpZCI6MTQzfQ","prevCursor": "eyJpZCI6MTAzfQ"}// Cursor wins for:// - Real-time feeds (new items insert without shifting indices)// - Large data (no OFFSET cost)// - Stable order (deduplication across pages)
Don't reinvent, follow conventions.
// FilteringGET /posts?status=publishedGET /posts?status=published&authorId=42GET /posts?createdAt[gte]=2026-01-01 // ranges with operator suffixes// Sorting (comma-separated, - for descending)GET /posts?sort=-createdAt,title// Field selection (sparse fieldsets, let client ask for less)GET /users/42?fields=name,email// Including related resourcesGET /posts/7?include=author,comments// JSON:API spec formalizes all of the above; follow it if you want.
Three options. Pick one + commit.
// Option 1: URL path versioning (most common, easiest to debug)GET /v1/usersGET /v2/users// Option 2: Header versioning (cleaner URLs; harder to debug)GET /usersHeader: API-Version: 2// Option 3: Content-type versioning (purist REST; rarely used)Accept: application/vnd.myapp.v2+json// Rules:// - Bump version on breaking changes (renamed/removed fields).// - Additive changes don't need a version bump.// - Document deprecation policy; give clients 6-12 months.
Verbs in URLs (POST /getUser is wrong; GET /users/42 is right). Mixed plural/singular: /users + /post (consistent plural). OFFSET pagination on infinite-scroll feeds (cursor is better). Skipping versioning (everything is v1 with no path; breaking changes break clients).
Sign in and purchase access to unlock this lesson.