File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 33
44The ` 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`."}}';
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+ ```
You can’t perform that action at this time.
0 commit comments