Documentation · Chapter 02

What happens
after Enter?

You type an address in the browser. Now let us follow the request until the page appears.

No prior technical vocabulary is required. Every new word is explained before it is used.

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.

phpaml — zsh
GET /books/12
GET

simply means: “give me this information”

/books/12

is 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.

  1. 1
    Application entrance

    Has a request arrived? PHPAML starts the project.

  2. 2
    Security checks

    Is this person allowed to continue?

  3. 3
    Route

    Which code can handle /books/12? A route is simply a rule connecting an address to an action.

  4. 4
    Controller

    What must happen to obtain the book? The controller organizes the work.

  5. 5
    Data and presentation

    Which book is it, and how should it appear?

  6. 6
    Response

    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.

phpaml — zsh
http://127.0.0.1:8910/books/12
http: the way to communicatehttp://
127.0.0.1: your own computerhost
8910: the door used by aml serveport
/books/12: the requested resourcepath

On 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.

In the path

/books/12 — le nombre 12 identifie le livre.

After the ? sign

/books?author=Ada — pratique pour filtrer ou rechercher.

Inside the sent content

A form can send a name, email, or new book without displaying it in the address.

In headers

Additional information: accepted format, language, session, or authentication.

The most useful HTTP actions.

Read a list or pageGET
Create new informationPOST
Replace existing informationPUT
Modify only one partPATCH
Delete informationDELETE

These 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.

2xx

The work succeeded. 200 indicates a normal response; 201 often indicates successful creation.

3xx

The browser must go elsewhere. 301 is a permanent move; 302 a temporary redirect.

4xx

The request cannot be fulfilled: incorrect address, permission, validation, or action.

5xx

The 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.

AVOID/src/controllers/book.php?id=12

The URL reveals internal organization and couples the browser to files.

PREFER/books/12

The 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 found

The application does not know this address.

405Action not allowed

The address exists, but not for the requested action.

500The code failed

The 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.