chris-doehring / enm-json-api-client
Abstract client-side php implementation of the json api specification (jsonapi.org)
Installs: 1 037
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 6
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- chris-doehring/enm-json-api-common: ^5.1
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- fakerphp/faker: ^1.10
- guzzlehttp/guzzle: ^7.0
- http-interop/http-factory-guzzle: ^1.0
- phpunit/phpunit: ^9.0
Suggests
- guzzlehttp/guzzle: A PSR 7 and 18 compatible, easy to use, PHP HTTP client
- http-interop/http-factory-guzzle: PSR 17 compatible guzzle factory library package
README
This package is abandoned. Please use dogado/json-api-client
instead.
Abstract client-side PHP implementation of the json api specification.
It's based on the original creation of the eosnewmedia team and the maintainer Philipp Marien.
Installation
composer require chris-doehring/enm-json-api-client
It's recommended to install guzzlehttp/guzzle
version ^7.0
as http-client and http-interop/http-factory-guzzle
for PSR-17 compatible factories.
composer require guzzlehttp/guzzle http-interop/http-factory-guzzle
You can also use any other HTTP client which implements PSR-18.
Usage
First you should read the docs at chris-doehring/enm-json-api-common where all basic structures are defined.
Your API client is an instance of Enm\JsonApi\Client\JsonApiClient
, which requires a PSR-18 HTTP client (Psr\Http\Client\ClientInterface
) to execute requests.
$client = new JsonApiClient( 'http://example.com/api', $httpClient, // instance of Psr\Http\Client\ClientInterface $uriFactory, // instance of Psr\Http\Message\UriFactoryInterface $requestFactory, // instance of Psr\Http\Message\RequestFactoryInterface $streamFactory, // instance of Psr\Http\Message\StreamFactoryInterface new Serializer(), new Deserializer() ); $request = $client->createGetRequest(new Uri('/myResources/1')); // will fetch the resource at http://example.com/api/myResources/1 $request->requestInclude('myRelationship'); // include a relationship $response = $client->execute($request); $document = $response->document(); $myResource = $document->data()->first(); // the resource fetched by this request $myIncludedResources = $document->included()->all(); // the included resources fetched with the include parameter