Download the PHP package rrd108/cakephp-json-api-exception without Composer
On this page you can find all versions of the php package rrd108/cakephp-json-api-exception. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rrd108/cakephp-json-api-exception
More information about rrd108/cakephp-json-api-exception
Files in rrd108/cakephp-json-api-exception
Package cakephp-json-api-exception
Short Description JsonApiException plugin for CakePHP
License MIT
Informations about the package cakephp-json-api-exception
JsonApiException plugin for CakePHP
Make your CakePHP 5 JSON REST API response more descriptive on errors.
For CakePHP 4 support use the CakePHP 4 branch
Supports CakePHP 5.0–5.3+. On CakePHP 5.3+ the plugin class auto-detection
uses JsonApiExceptionPlugin — no change required in your Application.php.
If you want a simple solution for token authentication for a CakePHP JSON REST API, then check this: CakePHP API Token Authenticator
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install is:
Then, to load the plugin either run the following command:
or manually add the following line to your app's src/Application.php file's bootstrap() function:
done :)
How to use
Assuming you have a CakePHP JSON REST API and you want to have more informative error messages and proper response codes.
If the save failed you will get a response like this.
You can us it with an array of entities also.
If the save failed you will get a response like this.
As at this point we do not have an id for the entity, the error messages can not contain it. So an empty array will be present in the errors array if an entity does not have any errors. So the number of the entity will match the number of the error entries, entity #3's error message will be the third element of the error array.