https://github.com/tembra/jsonapi-errors-php
A PHP implementation of JSON API Errors compliant format.
https://github.com/tembra/jsonapi-errors-php
Last synced: 4 months ago
JSON representation
A PHP implementation of JSON API Errors compliant format.
- Host: GitHub
- URL: https://github.com/tembra/jsonapi-errors-php
- Owner: tembra
- License: bsd-3-clause
- Created: 2016-06-27T22:22:15.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-30T18:35:16.000Z (about 10 years ago)
- Last Synced: 2024-11-22T09:08:40.169Z (over 1 year ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](LICENSE)
[](https://packagist.org/packages/tembra/jsonapi-errors-php)
[](https://packagist.org/packages/tembra/jsonapi-errors-php)
[](https://styleci.io/repos/62092362)
## Description
This framework agnostic package implements a simple and efficient way to throw or respond errors in JSON API specification **version v1.0** as described in [JSON API Errors](http://jsonapi.org/format/#errors). It also helps creating documentation for these errors on your application. It is based on 3rd party package [`neomerx/json-api`](https://github.com/neomerx/json-api) that fully implements the [JSON API Format](http://jsonapi.org/format/).
It greatly simplifies the error processing with high code quality.
Still framework agnostic, you can easily integrate it with [Laravel/Lumen](https://laravel.com) and [Dingo API](https://github.com/dingo/api).
## Milestone to v1.0
+ [x] Makes JSON API Errors as simple as calling a function
+ [x] Standardize the errors
+ [x] Provide most common error functions for HTTP Status Codes
+ [x] Throw an exception or return the JSON string
+ [x] Override JSON API Error Objects members
+ [ ] Support for Localization
+ [ ] Generate Documentation for Application Error Codes
+ [ ] Build PHPUnit tests
## Sample usage
Assuming you don't want a specific class to standardize the errors and also don't want the documentation or localization, you can use as simple as this:
```php
echo MyJsonApiErrors::badRequest([
827 => [
'title' => 'Another Error',
'detail' => 'Detailed error description'
]
], false);
```
will output **as string**
```json
{
"errors": [
{
"status": "400",
"code": "827",
"title": "Another Error",
"detail": "Detailed error description"
}
]
}
```
The first parameter is an associative array where `key` is the error `code` in JSON API compliant format and `value` is another associative array where `key/value` pairs are some others members that JSON API Error Objects may have.
The second parameter `false` is to define whether a `JsonApiException` should be thrown or only the JSON string should be returned.
**For more advanced usage please check out the [Wiki](https://github.com/tembra/jsonapi-errors-php/wiki)**.
## Questions?
Do not hesitate to contact me on tdt@mytdt.com.br or post an [issue](https://github.com/tembra/jsonapi-errors-php/issues).
## License
BSD 3-Clause. Please see [License File](LICENSE) for more information.
