Skip to main content

The Five Responses

Each single-resource response takes the resource instance in its constructor. ResourceListResponse additionally requires a PaginationResponseInterface.

Usage

Create / View / Update / Delete

Internally, each calls $animal->toArray($mode) with the matching mode constant, so per-mode field exclusions from $resource->excludeFromMode($mode) are applied automatically.

List

Or with offset / cursor pagination: swap in OffsetPaginationResponse / CursorPaginationResponse. The JsonRenderer adds the pagination key to the output automatically. Output shape:

OpenAPI Schema

You do not call addProperty(...) or setDescription(...) on these response classes. Their getDocumentation() returns an empty ApivalkResponseDocumentation as a placeholder; the actual schema for OpenAPI is built by ResponseDocumentationFactory::create($resource, $mode) during spec generation, using the resource’s properties and per-mode exclusions as the source of truth. This means a documentation change on the resource (adding a field, excluding one from list, etc.) updates every relevant CRUD response schema at once.

Writing a Custom Response

If you need a response shape that doesn’t fit these five envelopes (e.g. a bulk-import result), just return any subclass of AbstractApivalkResponse as normal — see the Response page. You’re not forced into the resource responses.