A single Composer command. The package is auto-discovered and there is nothing to register by hand.
Requirements
- PHP 8.1 or higher
- Laravel 10, 11, 12 or 13
Install
composer require mundoprogra/json-api
That is all. Laravel discovers the package on its own: at boot it hooks into exception handling and adds its middleware at the start of the global stack of the HTTP kernel, without touching bootstrap/app.php, Kernel or Handler.
It also works if your bootstrap/app.php replaces the global middleware list with withMiddleware (Laravel 11 to 13): the package middleware are added afterwards and end up at the start of the stack.
Publishing the configuration and the texts
It is optional. With these two commands you copy the configuration file and the error texts into your application, so you can change them:
php artisan vendor:publish --tag="json-api-config"
php artisan vendor:publish --tag="json-api-lang"
The first one creates config/json-api.php; every option is explained in Configuration. The second one copies the error texts (title and detail), which come in Spanish and English and are shown in the current Laravel locale.
Check that it works
With the application running, ask for a route that does not exist inside the api prefix:
curl -i -H "Accept: application/vnd.api+json" http://localhost:8000/api/does-not-exist
It must answer 404 with Content-Type: application/vnd.api+json and an errors document whose code is mundoprogra.json-api.route.not_found.
If you see Laravel's HTML error page instead, the route is not inside the package scope: by default it only acts on routes that start with api (or on the whole application with JSON_API_MODE=global). It is explained in How it switches on.