Adapters
The adapter runs the API at runtime. It translates between representations and HTTP — validating requests, building queries, and rendering responses.
What Adapters Do
Every request flows through the adapter:
- Validate — Check request against contract types
- Transform — Convert input for processing
- Query — Build and execute database queries
- Serialize — Convert records to response data
- Wrap — Structure the final response body
The adapter derives most behavior from representations. Filterable attributes become filter parameters. Sortable attributes become sort options. Associations become includable relations.
Capabilities
Adapters are built from capabilities — modular features like filtering, sorting, pagination. Each capability contributes to three phases:
| Phase | Runs | Purpose |
|---|---|---|
| API | Once at boot | Register shared types |
| Contract | Once per representation | Generate representation-specific types |
| Runtime | Each request | Process data |
Standard Adapter
Apiwork ships with a complete REST adapter. It provides:
- Filtering —
?filter[status][eq]=sent - Sorting —
?sort[created_at]=desc - Pagination — offset or cursor
- Includes — eager load associations
- Action Defaults — generated CRUD
For minor changes, extend the standard adapter.
Next Steps
- Standard Adapter — the built-in REST adapter
- Custom Adapters — build a custom adapter for JSON:API, HAL, or any format
See also
- Adapter::Base reference — all adapter methods and options