FIRST NEW WORD
A request is called a request.
When the browser asks the server for a page, developers call that message a request. It mainly contains the desired action and requested address.
GET /books/12GETsimply means: “give me this information”
/books/12is the part of the address that identifies book number 12
HTTP is the name of the shared rules browsers and servers use to communicate. You do not write these messages manually: the browser does it for you.
The request crosses several stations.
Like a letter passing through several hands before reaching the right department, the request moves one step at a time. Each station answers one simple question.
- 1Application entrance
Has a request arrived? PHPAML starts the project.
- 2Security checks
Is this person allowed to continue?
- 3Route
Which code can handle /books/12? A route is simply a rule connecting an address to an action.
- 4Controller
What must happen to obtain the book? The controller organizes the work.
- 5Data and presentation
Which book is it, and how should it appear?
- 6Response
The server finally sends the completed page back to the browser.
WORDS TO KNOW
A small dictionary before continuing
- Request
- The message sent by the browser.
- Route
- The rule connecting an address to the code that handles it.
- Controller
- The code that organizes the actions needed to answer.
- Response
- The result sent to the browser: a page, data, or an error.
Let us break down a complete address.
http://127.0.0.1:8910/books/12http://hostportpathOn a public website, a domain name generally replaces 127.0.0.1 and the port is hidden. The principle stays the same: the address lets the browser find a server and specify what it wants.
A request can carry information in three ways.
/books/12 — le nombre 12 identifie le livre.
/books?author=Ada — pratique pour filtrer ou rechercher.
A form can send a name, email, or new book without displaying it in the address.
Additional information: accepted format, language, session, or authentication.
The most useful HTTP actions.
GETPOSTPUTPATCHDELETEThese words describe intent. A route therefore combines an action and a path: GET /books does not mean the same thing as POST /books.
Quickly read response codes.
2xxThe work succeeded. 200 indicates a normal response; 201 often indicates successful creation.
3xxThe browser must go elsewhere. 301 is a permanent move; 302 a temporary redirect.
4xxThe request cannot be fulfilled: incorrect address, permission, validation, or action.
5xxThe application or server encountered an error while processing.
Why not open a PHP file directly?
Because a public address should not depend on the physical location of code. The /books/12 route can evolve without exposing src/controllers/BookController.php. The router also provides one place to control the HTTP method, authentication, and parameters.
/src/controllers/book.php?id=12The URL reveals internal organization and couples the browser to files.
/books/12The address describes the resource while PHPAML selects internal code.
What if something does not work?
The server sends a number called a status code. This number summarizes the result. You have probably already seen 404 on the Internet.
404Address not foundThe application does not know this address.
405Action not allowedThe address exists, but not for the requested action.
500The code failedThe application began working, then an error occurred.
BEGINNER QUESTIONS
You may be wondering…
Is a route a page?
Not exactly. A route is the rule deciding which code answers an address. That code can then build a page or return data.
Why GET?
GET says that the browser wants to read a resource. Other actions exist, such as POST for sending new information.
Why show error codes?
They indicate where to investigate: unknown address, forbidden action, or failure during execution.
CHECK YOUR UNDERSTANDING
A GET /users route exists. What should POST /users return when no POST route is declared?
Show the answer
405 Method Not Allowed
YOUR TURN
Classify these problems: unknown /books/12, controller throwing an exception, route available only through POST.
Show a hint
Expected answers: 404, 500, and 405.
SUMMARY
What to remember
- public/index.php boots the application.
- Middleware surrounds processing.
- The router uses method and path.
- Response always contains the final HTTP result.