What Is a Resource?
In Apivalk, a resource is a concrete subclass ofAbstractResource that describes one domain entity:
- its properties — including the identifier, declared as a regular property in
init(); - which properties are excluded from a given mode (e.g. hide the identifier from create request bodies, hide
weightfrom list responses); - the filters and sortings list endpoints expose;
- the OpenAPI tags for grouping.
Why Use Resources?
Without resources, building a full CRUD surface for one entity means authoring ~15 classes: five controllers, five request classes with property documentation, and five response classes. Resources collapse that to one resource class plus five thin controller subclasses. Benefits:- Zero duplicate documentation: identifier, properties, filters, and sortings are declared once.
- Built-in validation:
RequestValidationMiddlewarevalidates body, path, filters, and sort fields — all derived from the resource. - Built-in OpenAPI: request and response schemas are emitted for all five modes automatically.
- Shared response envelopes:
ResourceCreated/View/Updated/Deleted/ListResponsewrap thedatakey and pagination envelope for you. - Nested URLs: because each controller declares its own
buildRoute(), any URL structure is possible — including/users/{user_uuid}/authenticators/{authenticator_uuid}.
Big Picture
Learn More
Defining a Resource
How to subclass
AbstractResource: identifier, properties, filters, sortings, per-mode exclusions.Resource Controllers
The five CRUD controller bases, explicit
buildRoute(), and nested resource patterns.Resource Responses
The five pre-built response envelopes and how to attach pagination.