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.
Resources and URIs
Nouns, not verbs: /books, /books/42, /books/42/loans. Model your domain as resources, and fix the URLs that smell.
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.
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.
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.
Pagination, filters and errors
?page=2&limit=20, ?sort=-date, ?status=available: make a collection usable. And structured errors with problem+json (RFC 9457).
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.
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.
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.