Skip to content

Commit 53c7260

Browse files
authored
Update README.md
1 parent e243cc6 commit 53c7260

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ class Article extends ActiveRecord implements ResourceInterface
9292
}
9393
}
9494
```
95+
Controlling JSON API output
96+
------------------------------
97+
The JSON response is generated by the `tuyakhov\jsonapi\JsonApiResponseFormatter` class which will
98+
use the `yii\helpers\Json` helper internally. This formatter can be configured with different options like
99+
for example the `$prettyPrint` option, which is useful on development for
100+
better readable responses, or `$encodeOptions` to control the output
101+
of the JSON encoding.
102+
103+
The formatter can be configured in the `yii\web\Response::formatters` property of the `response` application
104+
component in the application configuration like the following:
105+
106+
```php
107+
'response' => [
108+
// ...
109+
'formatters' => [
110+
\yii\web\Response::FORMAT_JSON => [
111+
'class' => 'tuyakhov\jsonapi\JsonApiResponseFormatter',
112+
'prettyPrint' => YII_DEBUG, // use "pretty" output in debug mode
113+
'encodeOptions' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
114+
],
115+
],
116+
],
117+
```
95118
Enabling JSON Input
96119
---------------------------
97120
To let the API accept input data in JSON API format, configure the [[yii\web\Request::$parsers|parsers]] property of the request application component to use the [[tuyakhov\jsonapi\JsonApiParser]] for JSON input

0 commit comments

Comments
 (0)