Skip to content

A PHP Library to handle the response body from a JSON API Server in an OOP way.

License

Notifications You must be signed in to change notification settings

fcastilloes/json-api-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON API Client

Latest Version Software License Build Status Coverage Status Total Downloads

JSON API Client is a PHP Library to validate and handle the response body from a JSON API Server.

Format: JSON API 1.0

Install

Via Composer

$ composer require art4/json-api-client

Usage

See the documentation.

Using as reader

// The Response body from a JSON API server
$jsonapi_string = '{"meta":{"info":"Testing the JSON API Client."}}';

$document = \Art4\JsonApiClient\Utils\Helper::parse($jsonapi_string);

if ($document->has('meta') and $document->get('meta')->has('info'))
{
    echo $document->get('meta')->get('info'); // "Testing the JSON API Client."
}

// List all keys
var_dump($document->getKeys());

// array(
//   0 => "meta"
// )

Using as validator

JSON API Client 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`."}}';

try
{
	$document = \Art4\JsonApiClient\Utils\Helper::parse($wrong_jsonapi);
}
catch (\Art4\JsonApiClient\Exception\ValidationException $e)
{
	echo $e->getMessage(); // "A resource object MUST contain a type"
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ phpunit

Contributing

Please feel free to fork and sending Pull Requests.

Credits

License

GPL2. Please see License File for more information.

About

A PHP Library to handle the response body from a JSON API Server in an OOP way.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%