codemonster-ru/api-resource

JSON API resource and pagination primitives for Annabel applications.

Maintainers

Package info

github.com/codemonster-ru/api-resource

pkg:composer/codemonster-ru/api-resource

Statistics

Installs: 43

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-10 14:37 UTC

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.