cerbero/json-api-error

Laravel package to standardize API errors in compliance with the JSON:API spec.
5,292 2
Install
composer require cerbero/json-api-error
Latest Version:0.5.0
PHP:^8.1
License:MIT
Last Updated:Jan 28, 2025
Links: GitHub  ·  Packagist
Maintainer: cerbero

💥 JSON:API Error

Author PHP Version Laravel Version Build Status Coverage Status Quality Score PHPStan Level Total Downloads Latest Version Software License PER

{
  "errors": [
    {
      "status": "422",
      "title": "Unprocessable Content",
      "detail": "The name field must be a string.",
      "source": {
        "pointer": "/name"
      }
    },
    {
      "status": "422",
      "title": "Unprocessable Content",
      "detail": "The name field must be at least 2 characters.",
      "source": {
        "pointer": "/name"
      }
    }
  ]
}

Laravel package to standardize API error responses in compliance with the JSON:API spec, providing:

  • consistency: ensure uniform API error responses across all Laravel apps, adhering to a widely used standard
  • automation: handle Laravel-specific and common HTTP exceptions automatically
  • simplicity: focus solely on error responses without the need to implement the full JSON:API spec
  • zero configuration: install the package with no additional configuration required
  • customization: optionally register custom handlers, map errors to HTTP statuses or merge default data
  • localization: translate JSON:API errors into any language
  • testability: test error responses using the built-in testing tools
  • debugging: inspect the original message and trace when an unexpected error occurs

📦 Install

Via Composer:

composer require cerbero/json-api-error

🔮 Usage

[!NOTE] Work in progress... 🏗️

  • implement links
  • write documentation
  • reach 100% code coverage
  • tag stable version

📆 Change log

Please see CHANGELOG for more information on what has changed recently.

🧪 Testing

composer test

💞 Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

🧯 Security

If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.

🏅 Credits

⚖️ License

The MIT License (MIT). Please see License File for more information.

Related Packages

solidry/api-generator

PHP-code generator (based on OAS) for Laravel framework, with complete support o...

26,368 326
timacdonald/json-api

A Lightweight JSON:API Resource for Laravel

1,319,770 642
cloudcreativity/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

1,100,385 785
rjapi/raml-json-api

RAML-JSON-API PHP-code generator (based on RAML-types) for Laravel framework, wi...

416 326
fxmonster/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

6,758 0