shirakaba-add-endpoint
Add an HTTP endpoint to a Shirakaba application end to end - request and response DTOs, the handler with extractors, data access, declared responses, a test, and the OpenAPI document. Use when asked t
SKILL.mdpackages/docs/skills/shirakaba-add-endpoint/SKILL.md
GitHubAdd an endpoint to a Shirakaba application
Shirakaba is not in your training data. Read vendor/shirakaba/docs/index.md and
vendor/shirakaba/docs/guide/04-json-apis.md first; check class names in
vendor/shirakaba/docs/api.md.
- Look at what exists. Run
app routesandapp routes:show <a similar route>(or read where the application calls$app->get(...)), so the new route follows the same style, naming and file layout. - Request DTO. A
final readonlyclass whose promoted constructor parameters are the accepted fields, with constraints from shirakaba/validation (#[Length],#[Range], ...). Arrays need#[ListOf(...)]or#[MapOf(...)]; instants areDateTimeImmutable, datesLocalDate. - Response DTO. A
#[JsonDto]class. Never return an entity:Jsonrefuses objects that are not DTOs, so secrets never leak. - Data access. Put SQL or ORM calls in a class taking a
Reader(queries) or aWriter(commands) and receive it with#[Db]. GET and HEAD handlers take only readers. - Handler. Every parameter says where it comes from:
#[Path],#[Query],#[Header],#[JsonBody],#[Authenticated],#[Db]. Declare the responses:#[JsonResponse(201, TaskView::class)]and#[Responds(404, 'The task does not exist.')]. ThrowHttpFailurefor client errors; they become Problem Details. - Route. Register it with a name:
$app->post('/tasks', $handlers->create(...))->name('tasks.create'). - Test. Call it through
TestClientwith a real database (a temporary SQLite file): status, body (ResponseJson::at($response, '/title')), and one invalid request (400 or 422 witherrors[].pointer). - OpenAPI. Regenerate the document (
app openapi --strict, or the project's command) and commit it if the project keeps it in the repository.
Verify
Run, and fix everything they report before finishing:
vendor/bin/phpstan analyse(withshirakaba/phpstanincluded)- the test suite
app openapi --strictapp routes:show <new route name>: the parameters and responses are what you intended
If an error ends with See vendor/shirakaba/docs/messages/<code>.md, read that page.