Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eosnewmedia/json-api-client
Abstract client-side php implementation of the json api specification (jsonapi.org)
https://github.com/eosnewmedia/json-api-client
abstraction api api-client client json-api php php7
Last synced: about 2 months ago
JSON representation
Abstract client-side php implementation of the json api specification (jsonapi.org)
- Host: GitHub
- URL: https://github.com/eosnewmedia/json-api-client
- Owner: eosnewmedia
- License: mit
- Created: 2017-06-08T12:09:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T20:29:43.000Z (over 1 year ago)
- Last Synced: 2024-09-26T23:41:12.679Z (3 months ago)
- Topics: abstraction, api, api-client, client, json-api, php, php7
- Language: PHP
- Homepage: https://eosnewmedia.github.io/JSON-API-Client/
- Size: 63.5 KB
- Stars: 18
- Watchers: 7
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
JSON API Client
===============
[![Build Status](https://travis-ci.org/eosnewmedia/JSON-API-Client.svg?branch=master)](https://travis-ci.org/eosnewmedia/JSON-API-Client)Abstract client-side PHP implementation of the [json api specification](http://jsonapi.org/format/).
## Installation
```sh
composer require enm/json-api-client
```It's recommended to install `kriswallsmith/buzz` as http-client and `nyholm/psr7` for http factories.
```sh
composer require kriswallsmith/buzz nyholm/psr7
```You can also use any HTTP client which implements [PSR-18](https://www.php-fig.org/psr/psr-18/).
## Usage
First you should read the docs at [enm/json-api-common](https://eosnewmedia.github.io/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.
```php
$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```