Skip to content

Commit 7fa691d

Browse files
author
Philipp Marien
committed
Merge branch 'release/3.0.0'
2 parents 0d10354 + 4b6ee0e commit 7fa691d

15 files changed

+582
-1288
lines changed

.sensiolabs.yml

-1
This file was deleted.

.travis.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
language: php
22

33
php:
4-
- 7.0
5-
- 7.1
6-
7-
env:
8-
- JSON API Client
4+
- 7.2
95

106
before_script:
11-
- composer self-update
12-
- composer install
7+
- composer install
138

149
script: php vendor/bin/phpunit --coverage-text

README.md

+13-51
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
JSON API Client
22
===============
3-
[![Build Status](https://travis-ci.org/eosnewmedia/JSON-API-Client.svg?branch=master)](https://travis-ci.org/eosnewmedia/JSON-API-Client) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d6c28b22-fa18-4a74-8204-0e91d205781a/mini.png)](https://insight.sensiolabs.com/projects/d6c28b22-fa18-4a74-8204-0e91d205781a)
3+
[![Build Status](https://travis-ci.org/eosnewmedia/JSON-API-Client.svg?branch=master)](https://travis-ci.org/eosnewmedia/JSON-API-Client)
44

5-
Abstract client-side PHP implementation of the [json api specification](http://jsonapi.org/format/), based on the [PSR-7 HTTP message interface](http://www.php-fig.org/psr/psr-7/).
5+
Abstract client-side PHP implementation of the [json api specification](http://jsonapi.org/format/).
66

77
## Installation
88

@@ -27,62 +27,24 @@ If needed you can also implement the interface by yourself to use any HTTP clien
2727
## Usage
2828
First you should read the docs at [enm/json-api-common](https://eosnewmedia.github.io/JSON-API-Common/) where all basic structures are defined.
2929

30-
Your API client for sending requests to a JSON API and get validated responses as JSON API documents is an instance of
31-
`Enm\JsonApi\Client\JsonApiClient`, which requires a HTTP client (`Enm\JsonApi\HttpClient\HttpClientInterface`) to execute
32-
requests.
33-
34-
| Method | Return Type | Description |
35-
|--------------------------------------------------------------------------------------------------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------------|
36-
| createJsonApiRequest(string $type, string $id = '') | JsonApiRequestInterface | Create a new JSON API request object, needed for a delete request. |
37-
| createFetchRequest(string $type, string $id = '') | FetchRequestInterface | Create a new fetch request object, needed for fetch requests. |
38-
| createSaveSingleResourceRequest(ResourceInterface $resource, bool $patch = false) | SaveRequestInterface | Create a new save request object, needed for create or patch requests. |
39-
| fetch(FetchRequestInterface $request) | DocumentInterface | Execute a fetch request for one or many resources and transform the server response into a JSON API document. |
40-
| save(SaveRequestInterface $request) | DocumentInterface | Execute a save (create or patch) request and transform the server response into a JSON API document. |
41-
| delete(JsonApiRequestInterface $request) | DocumentInterface | Execute a delete request and transform the server response into a JSON API document. |
42-
| fetchRelationship(string $relationship, FetchRequestInterface $request, bool $onlyIdentifiers = false) | DocumentInterface | Execute a fetch request for a relationship and transform the server response into a JSON API document. |
43-
| follow(LinkInterface $link, array $headers = []) | DocumentInterface | Execute a fetch request which is defined by a JSON API link object and transform the server response into a JSON API document. |
44-
30+
Your API client is an instance of `Enm\JsonApi\Client\JsonApiClient`, which requires a HTTP client (`Enm\JsonApi\HttpClient\HttpClientInterface`) to execute requests.
4531

4632
```php
47-
// configure http client and api endpoint
48-
$guzzle = new Client(); // if you are using guzzle htttp
49-
$baseUri = 'http://example.com/api' // the base uri for all api requests
5033

51-
// create the api client
52-
$apiClient = new JsonApiClient($baseUri, new GuzzleAdapter($guzzle));
34+
$client = new JsonApiClient(
35+
'http://example.com/api',
36+
new GuzzleAdapter(new Client()), // with guzzle in this example...
37+
new Serializer(),
38+
new Deserializer()
39+
);
5340

54-
// create a fetch request to retrieve a single resource
55-
$request = $apiClient->createFetchRequest('myResourceType', 'myResource');
56-
$request->include('myRelationship'); // include a relationship
41+
$request = $client->createGetRequest(new Uri('/myResources/1')); // will fetch the resource at http://example.com/api/myResources/1
42+
$request->requestInclude('myRelationship'); // include a relationship
5743

58-
// get a response from server
59-
$document = $apiClient->fetch($request);
44+
$response = $client->execute($request);
6045

46+
$document = $response->document();
6147
$myResource = $document->data()->first(); // the resource fetched by this request
6248
$myIncludedResources = $document->included()->all(); // the included resources fetched with the include parameter
6349

64-
##############
65-
66-
// create a fetch request to retrieve all resource of a type
67-
$requestAll = $apiClient->createFetchRequest('myResourceType');
68-
69-
// get a response from server
70-
$collectionDocument = $apiClient->fetch($request);
71-
$resources = $collectionDocument->data()->all(); // all resources from the current response
72-
73-
##############
74-
75-
// create a new resource
76-
$resource = $apiClient->resource('examples', 'example-1');
77-
78-
$request = $apiClient->createSaveSingleResourceRequest($resource);
79-
$response = $apiClient->save($request);
80-
81-
// update the created resource
82-
$resource = $response->data()->first(); // get the created resource from response
83-
$resource->attributes()->set('title', 'Example');
84-
85-
$request = $apiClient->createSaveSingleResourceRequest($resource);
86-
$response = $apiClient->save($request);
87-
8850
```

composer.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
}
2121
},
2222
"require": {
23-
"enm/json-api-common": "^2.0",
24-
"psr/http-message": "^1.0",
25-
"psr/log": "^1.0",
26-
"guzzlehttp/psr7": "^1.0"
23+
"enm/json-api-common": "^3.0"
2724
},
2825
"require-dev": {
29-
"phpunit/phpunit": "^6.2",
26+
"phpunit/phpunit": "^7.0",
3027
"guzzlehttp/guzzle": "^6.0",
3128
"kriswallsmith/buzz": "^0.16.0"
3229
},

0 commit comments

Comments
 (0)