8 lessons · 83 min Intermediate

REST APIs — the contract that makes front and back talk

Resources, verbs, status codes, pagination, tokens: design a clean API, then build it in plain PHP. The direct follow-up to the HTTP course.

FR EN
Progress 0/8
1

What is an API? And REST?

An API is a contract between two programs. REST is a way to organise it on top of HTTP. The difference between the two, and the /getLivres lie.

9 min
2

Resources and URIs

Nouns, not verbs: /books, /books/42, /books/42/loans. Model your domain as resources, and fix the URLs that smell.

10 min
3

HTTP verbs: CRUD

GET, POST, PUT, PATCH, DELETE applied for real: which ones are idempotent, why it matters when the network retries, and PUT replacing vs PATCH touching.

10 min
4

Choosing the right status code

201 with its Location, 204 with no body, 400 vs 422, 409 for conflicts. And the forbidden anti-pattern: a 200 hiding an error in the body.

10 min
5

JSON: the data contract

Content-Type on send, Accept on request, and a clean JSON body on both sides. The contract that prevents front/back misunderstandings.

10 min
6

Pagination, filters and errors

?page=2&limit=20, ?sort=-date, ?status=available: make a collection usable. And structured errors with problem+json (RFC 9457).

11 min
7

Securing your API: tokens

API keys to identify an app, Bearer tokens for a user, 401 vs 403 applied, and why a key has no business in client-side JS.

10 min
8

Building a mini API in PHP

The capstone: /api/books in plain PHP, routing on the method, 201, 204, 422, problem+json. Plus OpenAPI to document it, and REST vs GraphQL and gRPC.

13 min

What you will learn

Model a domain as clean resources and URIs: nouns, not verbs

Apply verbs and idempotence, and answer with the right status code (201, 204, 422, 409)

Paginate, filter and sort a collection, and structure errors with problem+json (RFC 9457)

Secure with tokens (API key, Bearer) and build your documented mini API in plain PHP

Prerequisites: the HTTP course (status codes, request/response) and PHP basics for the capstone. Labs are simulated in the browser: curl terminal, predict, quizzes. Nothing to install.

Start lesson 1

Free · No signup · 9 minutes