Skip to content

Commit f5fa004

Browse files
committed
Update docs
1 parent bf95d97 commit f5fa004

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

docs/utils-helper.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
The `Utils\Helper` provides some useful methods to deal with JSON.
55

6-
### Parse a JSON API body
6+
### Parse a JSON API response body
77

8-
Assuming you have get a response from a JSON API server. Use `parse()` to work with the data.
8+
Assuming you have get a response from a JSON API server. Use `parseResponseBody()` to work with the data.
99

1010
```php
1111

@@ -41,7 +41,7 @@ This returns a [Document](objects-document.md) object which provided all content
4141
4242
### Validate a JSON API response body
4343

44-
JsonApiClient can be used as a validator:
44+
JsonApiClient can be used as a validator for a response body:
4545

4646
```php
4747
$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';
@@ -57,3 +57,22 @@ else
5757

5858
// echos 'string is invalid json api!'
5959
```
60+
61+
### Validate a JSON API request body
62+
63+
JsonApiClient can also be used as a validator for a request body:
64+
65+
```php
66+
$wrong_jsonapi = '{"data":{"type":"post","attributes":{"body":"The post body"}}}';
67+
68+
if ( \Art4\JsonApiClient\Utils\Helper::isValidRequestBody($wrong_jsonapi) )
69+
{
70+
echo 'string is valid.';
71+
}
72+
else
73+
{
74+
echo 'string is invalid json api!';
75+
}
76+
77+
// echos 'string is valid.'
78+
```

0 commit comments

Comments
 (0)