JsonApiClient is a PHP Library to validate and handle the response body from a JSON API Server.
Format: JSON API 1.0
Version 0.6.1 and below interprets the pagination links wrong. Make sure you are using the latest version of JsonApiClient. See #19, #23 and #26 for more information.
- Be 100% JSON API 1.0 spec conform
 - Handle/validate a server response body
 - Offer an easy way to retrieve the data
 - Be extendable and allow injection of classes/models
 - Handle/validate a client request body
 - Refactore and remove the deprecated code
 
Via Composer
$ composer require art4/json-api-clientSee the documentation.
// The Response body from a JSON API server
$jsonapi_string = '{"meta":{"info":"Testing the JsonApiClient library."}}';
$manager = new \Art4\JsonApiClient\Utils\Manager();
// Set this if you expect a resource creating request
$manager->setConfig('optional_item_id', true);
$document = $manager->parse($jsonapi_string);
if ($document->has('meta.info'))
{
    echo $document->get('meta.info'); // "Testing the JsonApiClient library."
}
// List all keys
var_dump($document->getKeys());
// array(
//   0 => "meta"
// )JsonApiClient can be used as a validator for JSON API contents:
$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';
if ( \Art4\JsonApiClient\Utils\Helper::isValidResponseBody($wrong_jsonapi) )
{
	echo 'string is valid.';
}
else
{
	echo 'string is invalid json api!';
}
// echos 'string is invalid json api!'Need more functionality? Want to directly inject your model? Easily extend JsonApiClient with the Factory.
Please see CHANGELOG for more information what has changed recently.
$ phpunitPlease feel free to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PSR-2.
GPL3. Please see License File for more information.