Documentation · Chapter 12

Build and verify a small Movies API.

This workshop builds a movies resource with list, detail, create, update, and delete operations.

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

Define the contract

Write sample requests and responses before code. Decide required title/year, public identifiers, pagination, and error statuses.

phpaml — zsh
aml test
aml routes
aml doctor --production
curl -H 'Accept: application/json' http://127.0.0.1:8910/api/movies

Implement the five operations

Implement index, show, store, update, destroy. Use Data transactions where several writes must succeed together.

Test from failure to success

Test unauthenticated, forbidden, invalid, absent, duplicate retry, rate-limited, and successful cases. Then run production diagnostics.

SUMMARY

What to remember

  • An API is a documented HTTP and JSON contract.
  • Request, controller, persistence, and resource have separate roles.
  • Authentication proves identity; abilities decide permission.
  • Idempotency, limits, CORS, and request IDs solve different problems.