API Platform in one lesson

What it generates

One small class can grow a full JSON API: list rows, show one row, create, update, and delete. The tool reads the class and wires the routes for you.

Docs and paging come along with the generated routes. You describe the shape, the tool builds the boring parts.

ApiResource note

Mark the class with the ApiResource attribute to expose it. That single marker is the whole starting point of this lesson.

The note below shows the marker on a plain class. Everything else in this lesson stays conceptual.

#[ApiResource] class Product { public int $id = 0; public string $name = "Plain"; }

Operations

Each action is called an operation: read the list, read one item, create, update, or remove. Disable the ones the app must not offer.

A shop catalog may allow reads but block deletes. Fewer operations mean a smaller attack face.

When it fits

Reach for it when the job is plain data in and out: admin panels, mobile back ends, and quick prototypes.

Skip it when answers need heavy custom logic on every call. A hand built controller stays clearer there.

Next: DQL

Article author: Arthur Isaev