/symfony-skills:rest-controller-conventionsfrom symfony-skills
Provides conventions for hand-rolled Symfony REST controllers: routing attributes, HTTP status codes, request payload mapping, serialization groups, pagination, and versioning.
Ships in symfony-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
final class per resource, #[Route] prefix on the class.layered-architecture).#[MapRequestPayload] and query params with #[MapQueryString] into DTOs.JsonResponse via $this->json(...) with explicit status codes.#[Route('/api/orders')]
final class OrderController extends AbstractController
{
public function __construct(private readonly OrderService $orders) {}
#[Route('', methods: ['GET'])]
public function list(#[MapQueryString] OrderListQuery $query): JsonResponse
{
$page = $this->orders->list($query);
return $this->json($page, context: ['groups' => ['order:read']]);
}
#[Route('/{id}', methods: ['GET'])]
public function show(Uuid $id): JsonResponse
{
return $this->json(
$this->orders->get($id),
context: ['groups' => ['order:read', 'order:detail']],
);
}
#[Route('', methods: ['POST'])]
public function create(#[MapRequestPayload] CreateOrderRequest $request): JsonResponse
{
$order = $this->orders->createOrder($request);
return $this->json(
OrderResponse::fromEntity($order),
Response::HTTP_CREATED,
['Location' => $this->generateUrl('order_show', ['id' => $order->getId()])],
['groups' => ['order:read']],
);
}
#[Route('/{id}', methods: ['DELETE'])]
public function delete(Uuid $id): JsonResponse
{
$this->orders->cancel($id);
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
}
}
| Situation | Status |
|---|---|
| Successful GET | 200 OK |
| Resource created | 201 Created + Location header |
| Accepted, processed async | 202 Accepted |
| Successful DELETE / no body | 204 No Content |
| Validation failed | 422 Unprocessable Entity |
| Malformed JSON | 400 Bad Request |
| Unauthenticated | 401 Unauthorized |
| Authenticated but forbidden | 403 Forbidden |
| Not found | 404 Not Found |
| Conflict (duplicate, version) | 409 Conflict |
Don't return 200 for everything. Map domain exceptions to status codes in an exception listener (see problem-details-rfc9457).
Never serialize a Doctrine entity straight to the client without scoping. Either map to a response DTO or apply #[Groups] and pass the group in the serialization context.
// On the entity / DTO
#[Groups(['order:read'])]
private string $customerEmail;
#[Groups(['order:detail'])] // only on the detail endpoint
private array $internalNotes;
#[MapRequestPayload] deserializes and validates the DTO (via the Validator). On constraint failure it throws automatically → your exception listener turns it into a 422.
public function create(#[MapRequestPayload] CreateOrderRequest $request): JsonResponse
Validate query params the same way with #[MapQueryString]. See dto-and-validation.
Return a stable envelope, never a bare array, so you can add metadata without a breaking change:
{
"data": [ ... ],
"page": 1,
"perPage": 20,
"total": 137
}
return $this->json(new PaginatedResponse($items, $page, $perPage, $total), context: ['groups' => ['order:read']]);
Cap perPage server-side. For deep pages, prefer keyset pagination (see doctrine-query-optimization).
/orders, /orders/{id}, /orders/{id}/lines./orders POST, not /createOrder).#[Route('/{id}', requirements: ['id' => Requirement::UUID])].$this->json($entity) without groups — scope with #[Groups] or map to a DTO; otherwise lazy associations serialize and leak fields.200 for created/deleted resources — use 201 (+ Location) and 204.json_decode($request->getContent())) — use #[MapRequestPayload] + DTO./getOrders, /createOrder) — use nouns + HTTP methods.NotFoundException in the controller — let the exception listener map it to 404.{id} to UUID to avoid route collisions.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub fatonh/symfony-skills --plugin symfony-skills17 skills in this plugin
/api-platform-resourcesUse when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.
/bundle-organizationUse when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).
/console-commandsUse when creating or refactoring Symfony console commands — never extends Command. On Symfony 8.1+ put #[AsCommand] on a method of a service class (even for a single command); on 7.x use the invokable attribute class. Also covers typed CLI inputs via value resolvers and #[MapInput] DTOs. Use when the task mentions console command, #[AsCommand], bin/console, #[Argument], #[Option], or a CLI task.
Other plugins' skills for the same job