codemonster-ru / api-resource
JSON API resource and pagination primitives for Annabel applications.
v1.0.0
2026-06-10 14:37 UTC
Requires
- php: >=8.2
- codemonster-ru/http: ^2.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2026-06-10 15:28:47 UTC
README
JSON resource and simple pagination primitives for Annabel applications.
use Codemonster\ApiResource\JsonResource; final class UserResource extends JsonResource { public function toArray(): array { return [ 'id' => $this->resource->getKey(), 'name' => $this->resource->name, ]; } } return (new UserResource($user))->response();
Collections and existing database pagination results use the same resource:
return UserResource::collection(User::all())->response(); return UserResource::paginated( User::query()->simplePaginate(20, $page), '/api/users', ['filter' => 'active'], )->response();
Paginated responses contain data, links.prev, links.next, and
meta.current_page / meta.per_page.