2017 © Pedro Peláez
 

library json-api-client

JSON API client

image

art4/json-api-client

JSON API client

  • Friday, June 15, 2018
  • by Art4
  • Repository
  • 12 Watchers
  • 95 Stars
  • 165,091 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 14 Forks
  • 1 Open issues
  • 17 Versions
  • 15 % Grown

The README.md

JsonApiClient

Latest Version Software License Build Status codecov Total Downloads, (*1)

JsonApiClient :construction_worker_woman: is a PHP Library to validate and handle the response body from a JSON API Server., (*2)

Format: JSON API 1.0, (*3)

:checkered_flag: Goals

  • ✅ Be 100% JSON API 1.0 spec conform
  • ⬜ Be open for new spec minor versions (see #90)
  • ✅ Handle/validate a server response body
  • ✅ Handle/validate a client request body
  • ✅ Offer an easy way to retrieve the data
  • ✅ Allow extendability and injection of classes/models

:package: Install

Via Composer, (*4)

``` bash $ composer require art4/json-api-client, (*5)


### :building_construction: Upgrade to v1 **Version 1.0 is finally released.** :tada: After version 0.8.0 there where no breaking changes. Every change was backward compatible and every functionality that was removed in v1.0 only triggers a deprecation warning in v0.10. To upgrade from v0.x to v1 just update to 0.10.2 and resolve all deprecation warnings. Or in 3 simple steps: 1. Update your composer.json to `"art4/json-api-client": "^0.10.2"` 2. Make your code deprecation warnings free 3. Upgrade your composer.json to `"art4/json-api-client": "^1.0"` without breaking your app (Compare the [Symfony upgrade documentation](https://symfony.com/doc/current/setup/upgrade_major.html)) ## :rocket: Usage See the [quickstart guide](docs/helper-parser.md) or the [documentation](docs/README.md). ### Using as parser ```php use Art4\JsonApiClient\Exception\InputException; use Art4\JsonApiClient\Exception\ValidationException; use Art4\JsonApiClient\Helper\Parser; // The Response body from a JSON API server $jsonapiString = '{"meta":{"info":"Testing the JsonApiClient library."}}'; try { // Use this if you have a response after calling a JSON API server $document = Parser::parseResponseString($jsonapiString); // Or use this if you have a request to your JSON API server $document = Parser::parseRequestString($jsonapiString); } catch (InputException $e) { // $jsonapiString is not valid JSON } catch (ValidationException $e) { // $jsonapiString is not valid JSON API }

Note: Using Art4\JsonApiClient\Helper\Parser is just a shortcut for directly using the Manager., (*6)

$document implements the Art4\JsonApiClient\Accessable interface to access the parsed data. It has the methods has($key), get($key) and getKeys()., (*7)

// Note that has() and get() have support for dot-notated keys
if ($document->has('meta.info'))
{
    echo $document->get('meta.info'); // "Testing the JsonApiClient library."
}

// you can get all keys as an array
var_dump($document->getKeys());

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

Using as validator

JsonApiClient can be used as a validator for JSON API contents:, (*8)

use Art4\JsonApiClient\Helper\Parser;

$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';

if ( Parser::isValidResponseString($wrong_jsonapi) ) {
// or Parser::isValidRequestString($wrong_jsonapi)
    echo 'string is valid.';
} else {
    echo 'string is invalid json api!';
}

// echoes 'string is invalid json api!'

Extend the client

Need more functionality? Want to directly inject your model? Easily extend JsonApiClient with the Factory., (*9)

:loud_sound: Changelog

Please see CHANGELOG for more information what has changed recently., (*10)

:wrench: Contributing

Please feel free to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PER-CS2.0., (*11)

This projects comes with a docker-compose.yml where all tools for development are available., (*12)

Run docker compose build to build the image. Once you've build it, run docker compose up -d to start the container in the background., (*13)

Run docker compose exec -u 1000 php bash to use the bash inside the running container. There you can use all tools, e.g. composer with composer --version, (*14)

Use exit to logout from the container and docker compose stop to stop the running container., (*15)

All following commands can be run inside the running docker container., (*16)

:white_check_mark: Testing

Run PHPUnit for all tests:, (*17)

``` bash $ composer run phpunit, (*18)


Run PHPStan for static code analysis: ``` bash $ composer run phpstan

Let PHPUnit generate a HTLM code coverage report:, (*19)

``` bash $ composer run coverage, (*20)


You can find the code coverage report in `.phpunit.cache/code-coverage/index.html`. ### :white_check_mark: REUSE The [REUSE Helper tool](https://reuse.software/dev/) makes licensing easy for humans and machines alike. It downloads the full license texts, adds copyright and license information to file headers, and contains a linter to identify problems. Check all files for REUSE spec compliance: ``` bash composer run reuse-lint

Run this command to annotate PHP files in src and tests folders:, (*21)

bash composer run reuse-annotate, (*22)

:heart: Credits

:page_facing_up: License

GPL3. Please see License File for more information., (*23)

The Versions

15/06 2018

dev-master

9999999-dev https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL3 GPL2 GPL-3.0-or-later

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

api parser json validator client reader json-api

27/01 2018

dev-namespace_refactoring

dev-namespace_refactoring https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL3 GPL-3.0-or-later

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

api parser json validator client reader json-api

21/12 2017

0.9.1

0.9.1.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL3

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

api parser json validator client reader json-api

06/06 2017

0.9

0.9.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL3

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

api parser json validator client reader json-api

01/06 2017

0.8.1

0.8.1.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

api json validator client reader json-api

29/05 2017

0.8

0.8.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

api json validator client reader json-api

24/11 2016

0.7

0.7.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

15/11 2016

dev-Item-ID_optional

dev-Item-ID_optional https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

26/04 2016

0.6.3

0.6.3.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

15/04 2016

0.6.2

0.6.2.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

28/12 2015

0.6.1

0.6.1.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

06/11 2015

0.6

0.6.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

12/10 2015

0.5

0.5.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

01/09 2015

0.4

0.4.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

24/08 2015

0.3

0.3.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

12/08 2015

0.2

0.2.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api

11/08 2015

0.1

0.1.0.0 https://github.com/Art4/json-api-client

JSON API client

  Sources   Download

GPL2

The Requires

  • php >=5.4

 

The Development Requires

api json validator client reader json-api