Documentation · Chapter 12

Create and organize a PHPAML API.

create-api prepares routes, controllers, request validation, resources, middleware, token storage, and production defaults.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

Generate the project

The command installs the API template and configures /api, JSON middleware, CORS, tokens, and generated examples.

phpaml — zsh
aml create-api movies-api
cd movies-api
aml routes
aml serve

Route to controller actions

Routes remain explicit. A path parameter such as {id} becomes a request attribute. Different methods may share a path but perform different actions.

Keep layers separate

Request classes validate input, controllers orchestrate, Data persists, and resource classes select public fields. Do not return database internals directly.