Documentation Index
Fetch the complete documentation index at: https://docs.apivalk.com/llms.txt
Use this file to discover all available pages before exploring further.
Creating a Response
Every response class must extendAbstractApivalkResponse and implement:
getStatusCode(): Returns the HTTP status code (e.g., 200, 201, 404).getDocumentation(): Defines the schema for OpenAPI generation.toArray(): Returns the data to be rendered (usually as JSON).
Example
Resource Responses (CRUD)
When a controller extends one of theAbstract*ResourceController bases, pair it with the matching pre-built response from Http/Response/Resource/:
| Response class | Status | Used by |
|---|---|---|
ResourceCreatedResponse | 201 | AbstractCreateResourceController |
ResourceViewResponse | 200 | AbstractViewResourceController |
ResourceListResponse | 200 | AbstractListResourceController |
ResourceUpdatedResponse | 200 | AbstractUpdateResourceController |
ResourceDeletedResponse | 200 | AbstractDeleteResourceController |
toArray($mode) output under a data key. ResourceListResponse additionally takes a PaginationResponseInterface and emits the standard pagination envelope. The OpenAPI schema for these responses is generated from the AbstractResource declaration — you do not author response documentation by hand.
See Resource Responses.
Built-in Error Responses
Apivalk provides several pre-defined error responses for common scenarios:BadRequestApivalkResponse(400)UnauthorizedApivalkResponse(401)ForbiddenApivalkResponse(403)NotFoundApivalkResponse(404)MethodNotAllowedApivalkResponse(405)TooManyRequestsApivalkResponse(429)InternalServerErrorApivalkResponse(500)BadValidationApivalkResponse(422) - Used automatically by theRequestValidationMiddleware.
Headers
You can add custom headers to any response object:Automatic Rate Limit Headers
When the Rate Limit Middleware is active, Apivalk automatically appends rate limit information to the response headers. This ensures that clients are always aware of their current quota and remaining requests. The following headers are automatically added:X-RateLimit-Limit: The maximum number of requests allowed in the current window.X-RateLimit-Remaining: The number of requests left for the current window.X-RateLimit-Reset: The time at which the current rate limit window resets (UTC timestamp).
Retry-After header is also included.
Pagination
If a route has pagination enabled, you can attach a pagination response object to your response. This will automatically inject thepagination metadata into the JSON output and the OpenAPI documentation.
Rendering
TheJsonRenderer is the default renderer. It takes the array from toArray() and converts it to a JSON string, handling headers and status codes automatically.