Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Json Api Laravel Package

haddowg/json-api

Laravel package for building spec-compliant JSON:API endpoints. Handles resource serialization, relationship inclusion, sparse fieldsets, filtering, sorting, pagination, and standardized error responses, with Eloquent integration and validation for consistent, predictable APIs.

View on GitHub
Deep Wiki
Context7

Framework agnostic JSON:API library for PHP

Frequently asked questions about Json Api
What is haddowg/json-api and what problem does it solve for Laravel APIs?
It is a PHP package that adds JSON:API specification support to Laravel applications. Instead of hand-rolling serialization logic, you get resource serialization with type, id, attributes, and relationships, plus compound documents, sparse fieldsets, pagination links, and standardized error objects. This keeps your endpoints consistent and interoperable with JSON:API clients. It is aimed at teams that want predictable, spec-driven responses built on top of Eloquent models.
How do I install haddowg/json-api in a Laravel application?
Install it through Composer with composer require haddowg/json-api. After that, follow the package documentation to register any service provider or configuration it ships with, then start defining resources for your Eloquent models. Because it is a Composer package, it fits into a standard Laravel project structure without extra build tooling.
Does haddowg/json-api support relationships and compound documents with ?include=?
Yes. The package handles compound documents via included relationships, so a request such as ?include=author,comments can return related resources in the top-level included array rather than nesting them inside each resource. Relationship data and links follow JSON:API conventions, so clients can resolve them predictably. You declare which relationships are available for inclusion on your resources.
How do sparse fieldsets work in this package?
Sparse fieldsets let clients request only the attributes and relationships they need per resource type, for example ?fields[articles]=title,author. The package reads those field parameters and limits the serialized output accordingly, which reduces payload size and over-fetching. You define the available fields on each resource so unsupported fields are handled consistently.
Can I paginate JSON:API responses with links and meta?
Yes. Pagination and links follow the JSON:API conventions, so responses include the expected links object and pagination-related meta rather than an ad hoc structure. This lets clients page through collections using standard top-level links. It applies to Eloquent-backed collections that you expose through the package's resources.
How does filtering and sorting fit into the package?
The package provides filtering support alongside sparse fieldsets, so query parameters can map onto your Eloquent queries instead of being handled with custom parsing in every controller. Sorting is also part of the advertised capabilities. You remain in control of which filters and sorts are exposed, which keeps requests predictable and avoids unintended query behavior.
Which Laravel and PHP versions does haddowg/json-api support?
Version support is defined by the package's Composer constraints, so check the require section in its composer.json or the Packagist listing for the exact PHP and Laravel versions covered. Matching those constraints against your application's version is the safest way to confirm compatibility before installing. If you are on an older Laravel release, verify that the package version you pin still supports it.
How are errors and validation failures returned by this package?
Errors are returned as JSON:API error objects, giving clients a standardized structure with fields such as status, title, and detail instead of arbitrary error payloads. This includes validation failures, which are surfaced through the same error format so consumers only need one error-handling path. Keeping errors spec-compliant is one of the main reasons to use the package rather than custom responses.
How should I test JSON:API endpoints built with haddowg/json-api?
Use Laravel's HTTP testing helpers to call your endpoints and assert the JSON structure of the response, including the data, type, id, attributes, and relationships keys. Add coverage for query parameter behavior such as include, sparse fieldsets, filtering, and pagination so regressions in document shape are caught early. Testing the serialized output rather than internal classes keeps your tests aligned with what API clients actually consume.
Is haddowg/json-api a good production choice, and what are the alternatives?
It is a reasonable fit if you want JSON:API compliance in Laravel without writing serialization logic yourself, and its feature set covers the parts of the spec most APIs need. Before committing, review the repository's recent activity, open issues, and release history to judge maintenance for your risk tolerance, and pin a version in composer.json. Alternatives include building on Laravel's own API Resources for full control, or adopting a different JSON:API package if you need features or a support model this one does not provide.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect