Answer the question
In order to leave comments, you need to log in
How to make json format in api?
I have such a question in postman, I get a json response, but let's say when I open this page in the browser I get the xml format, should it be so or not?
In config/main.php
'components' => [
....
'response' => [
'formatters' => [
\yii\web\Response::FORMAT_JSON => [
'class' => 'yii\web\JsonResponseFormatter',
]
]
],
Answer the question
In order to leave comments, you need to log in
When the browser makes a request to the server, it indicates which content types it prefers in the form of a header
. In the framework, REST controllers are configured for two data types - JSON and XML
. the browser has indicated it as the preferred one. If you want to leave only JSON, then reconfigure the controllers. And then even in the browser there will be JSON.
Read full description: https://github.com/yiisoft/yii2/blob/master/docs/g...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question