Skip to content

Feat: Add API Resource and Collection layer for consistent JSON responses #22

@3m1n3nc3

Description

@3m1n3nc3

Background: Standardize API responses with Resources (single model) and Collections (lists + pagination + meta).

Tasks:

  • Your core implementation will live in the @h3ravel/http package directory.
  • Create Resource base class (toArray, with/without relationships).
  • Create Collection base class supporting pagination, meta, links.
  • Integrate with response helpers to automatically detect Resource/Collection and set JSON structure.
  • Provide helpers for transforming Arquebus models and relations.
  • Add tests demonstrating Resource and Collection usage (single resource, collection paginated).
  • Add example usage docs in http documentation.

Acceptance criteria:

  • Returning a Resource from a controller yields { data: { ... } }.
  • Returning a Collection yields { data: [...], meta: {...}, links: {...} }.
  • Tests cover transformations and pagination meta generation.
  • Interface mirrors laravel as much as possible, creating the familiar DX while also adding it own unique twists and turns.

Difficulty: medium

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions