Skip to content

Commit 0ebff9c

Browse files
committed
Update PHP requirements und docs
1 parent 81f9d89 commit 0ebff9c

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Version 0.6.1 and below interprets the pagination links wrong. Make sure you are
2121
* [x] Offer an easy way to retrieve the data
2222
* [x] Be extendable and allow injection of classes/models
2323
* [ ] Offer access to included resources through identifier
24-
* [ ] Handle/validate a client request body
24+
* [x] Handle/validate a client request body
2525

2626
## Install
2727

@@ -43,6 +43,9 @@ $jsonapi_string = '{"meta":{"info":"Testing the JsonApiClient library."}}';
4343

4444
$manager = new \Art4\JsonApiClient\Utils\Manager();
4545

46+
// Set this if you expect a resource creating request
47+
$manager->setConfig('optional_item_id', true);
48+
4649
$document = $manager->parse($jsonapi_string);
4750

4851
if ($document->has('meta.info'))

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": "^5.4 || ^7.0"
16+
"php": "^5.5 || ^7.0"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^4.8.35 || ^6.0"

docs/utils-helper.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ This returns a [Document](objects-document.md) object which provided all content
2121
>
2222
> See more about Exceptions in the [Exception section](exception-introduction.md).
2323
24+
### Parse a JSON API request body
25+
26+
Assuming you have get a request for creating a new resource. In this case the `id` in the resource item can be missed and you have to tell the Manager about this case. Use `parseRequestBody()` to work with the data.
27+
28+
```php
29+
30+
// The requst body from a client
31+
$jsonapi_string = '{"data":{"type":"posts","attributes":{"title":"Post Title"}}}';
32+
33+
$document = \Art4\JsonApiClient\Utils\Helper::parseRequestBody($jsonapi_string);
34+
```
35+
36+
This returns a [Document](objects-document.md) object which provided all contents.
37+
38+
> **Note:** If `$jsonapi_string` contains not valid JSON or JSON API a [Exception\ValidationException](exception-introduction.md#exceptionvalidationexception) will be thrown.
39+
>
40+
> See more about Exceptions in the [Exception section](exception-introduction.md).
41+
2442
### Validate a JSON API response body
2543

2644
JsonApiClient can be used as a validator:

docs/utils-manager.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ This returns a [Document](objects-document.md) object which provided all content
2121

2222
> **Note:** If `$jsonapi_string` contains not valid JSON or JSON API a [Exception\ValidationException](exception-introduction.md#exceptionvalidationexception) will be thrown.
2323
24+
### Parse a JSON API string for creating a new resource
25+
26+
Assuming you have get a request for creating a new resource. In this case the `id` in the resource item can be missed and you have to tell the Manager about this case.
27+
28+
```php
29+
30+
// The request body from a client
31+
$jsonapi_string = '{"data":{"type":"posts","attributes":{"title":"Post Title"}}}';
32+
33+
$manager = new \Art4\JsonApiClient\Utils\Manager();
34+
35+
// Set this to `true`
36+
$manager->setConfig('optional_item_id', true);
37+
38+
$document = $manager->parse($jsonapi_string);
39+
```
40+
41+
This returns a [Document](objects-document.md) object which provided all contents.
42+
43+
> **Note:** If `$jsonapi_string` contains not valid JSON or JSON API a [Exception\ValidationException](exception-introduction.md#exceptionvalidationexception) will be thrown.
44+
2445
### Working with a factory
2546

2647
You can set a custom [Factory](utils->factory.md) to the manager through `setFactory()` or the constructor.

0 commit comments

Comments
 (0)