Documentation · Chapter 02

Follow a request
end to end.

A URL does not directly open a controller. Several steps transform the browser request into an HTTP response.

STARTING POINT

The browser makes a request.

phpaml — zsh
GET /products/42 HTTP/1.1
Host: 127.0.0.1:8910
Accept: text/html

GET is the HTTP method. /products/42 is the path. Accept indicates the desired format. PHPAML turns this raw information into a Request object so your code does not read PHP globals directly.

Six steps, six responsibilities.

  1. 1
    public/index.php

    Receives Web requests and boots the application.

  2. 2
    Middleware

    Apply security, session, or authentication before the action.

  3. 3
    Router

    Matches the method and path against registered routes.

  4. 4
    Controller

    Coordinates the requested use case.

  5. 5
    Model and view

    Obtain data and build its representation.

  6. 6
    Response

    Defines status, headers, and returned body.

What if nothing matches?

404Unknown route

No registered path matches.

405Method not allowed

The path exists, but not for that HTTP method.

500Application error

The route exists, but processing failed.

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

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.