/symfony-hexagonal:symfony-api-responsefrom symfony-hexagonal
Standardizes Symfony REST API responses with {result, error, extra, status} JSON format, thin controllers using #[MapRequestPayload]/#[MapQueryString], ApiResponseTrait, and exception subscriber for Messenger failures.
Ships in symfony-hexagonal. 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.
Read when SKILL.md points to them.
You are an expert in building standardized REST APIs within Symfony hexagonal architecture.
| Feature | Requires | Fallback |
|---|---|---|
#[MapRequestPayload], #[MapQueryString] | Symfony 6.3 | json_decode + ValidatorInterface (see validation skill) |
Symfony\Component\Routing\Attribute\Route | Symfony 6.2 | Routing\Annotation\Route |
#[MapUploadedFile] | Symfony 7.1 | $request->files->get() |
#[MapRequestHeader], variadic #[MapRequestPayload] Dto ...$items | Symfony 8.1 | $request->headers->get(), type: Dto::class array |
Never call $request->get() (removed in Symfony 8).
ALL API responses use this format:
{
"result": null,
"error": null,
"extra": null,
"status": 200
}
| Field | Type | Description |
|---|---|---|
result | mixed | Success data (null on error) |
error | ?object | Error details {code, message, details?} (null on success) |
extra | ?object | Metadata: pagination, debug info |
status | int | HTTP status code (same as the response status) |
{
"result": {"id": "0199a3c2-...", "name": "John"},
"error": null,
"extra": null,
"status": 200
}
{
"result": null,
"error": {"code": "USER_NOT_FOUND", "message": "User not found"},
"extra": null,
"status": 404
}
{
"result": null,
"error": {"code": "INTERNAL_ERROR", "message": "Something went wrong"},
"extra": {"debug": {"exception": "...", "file": "...", "line": 42, "trace": "..."}},
"status": 500
}
In production, 5xx messages are generic: never leak exception messages or traces.
Because every response carries a body, there is no 204 No Content in this API: successful writes without data return 200 with "result": null (or 202 for async commands).
Controllers are thin: map input, dispatch, format output.
namespace App\Presentation\{Module}\API;
use App\Presentation\Shared\ApiResponseTrait;
use App\Presentation\Shared\Bus\CommandBus;
use App\Presentation\Shared\Bus\QueryBus;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
#[Route('/api/{module}')]
final class {Entity}Controller
{
use ApiResponseTrait;
public function __construct(
private readonly CommandBus $commandBus,
private readonly QueryBus $queryBus,
) {
}
#[Route('', methods: ['POST'])]
#[IsGranted('ROLE_{MODULE}_CREATE')] // ALWAYS include
public function create(#[MapRequestPayload] Create{Entity}Request $request): JsonResponse
{
$id = $this->commandBus->dispatch(new Create{Entity}(/* from $request */));
return $this->created(['id' => $id]);
}
}
See references/ for detailed guides:
payload-schema.md - ApiResponseTrait, request DTOs, full controller exampleexception-handling.md - ApiExceptionSubscriber, domain error mapping, validation errorsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
symfony-api, rest-api, json-response, error-handling, request-dto
npx claudepluginhub aligundogdu/symfony-hexagonal-skill --plugin symfony-hexagonal10 skills in this plugin
/symfony-cqrs-handlersSymfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp/symfony-doctrine-persistenceDoctrine persistence for Symfony hexagonal architecture (ORM 2.x/3.x, DBAL 3/4, DoctrineBundle 2/3): repository adapters, XML mapping in Infrastructure, embeddables, enums, custom DBAL types, native lazy objects, migrations, transactions, read models with DBAL QueryBuilder, strict no-native-SQL rule. Use when: doctrine, repository, persistence, database, mapping, migration, ORM, entity manager, DBAL, transaction, query builder, pagination/symfony-domain-modelingSymfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status/symfony-hexagonal-architectureSymfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade/symfony-messenger-asyncSymfony Messenger async processing and Symfony Scheduler instead of cron: transports, routing (#[AsMessage] 7.2+), retry with backoff and jitter, failure transport, idempotency keys, DeduplicateStamp (7.3+), workers, supervisor, scheduled commands with stateful/locked schedules. Use when: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task, idempotency, deduplication/symfony-ports-adaptersSymfony ports and adapters: port interfaces in Domain, adapter implementations in Infrastructure, dependency injection, autowiring, services.yaml aliases, #[AsAlias], environment-specific and decorated adapters, in-memory test adapters. Use when: port, adapter, interface, repository interface, DI, autowiring, dependency injection, services.yaml, binding, decorator, AsAliasOther plugins' skills for the same job