<?php use yii\web\Response; $params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php'); return ['id' => 'app-api', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'api\\controllers', 'bootstrap' => ['log'], 'defaultRoute' => 'v1/default', 'modules' => ['v1' => ['basePath' => '@app/modules/v1', 'class' => 'api\\modules\\v1\\Module']], 'bootstrap' => [['class' => yii\filters\ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON, 'application/xml' => Response::FORMAT_XML]]], 'components' => ['log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false], 'request' => ['parsers' => ['application/json' => 'yii\\web\\JsonParser']], 'response' => ['class' => 'yii\\web\\Response', 'on beforeSend' => function ($event) { $response = $event->sender; if ($response->data !== null && ($exception = Yii::$app->getErrorHandler()->exception) !== null) { $response->data = ['error' => $response->data]; } }]], 'params' => $params];
<?php return ['id' => 'app-api', 'name' => '', 'controllerNamespace' => 'api\\controllers', 'defaultRoute' => 'product', 'components' => ['urlManager' => ['enablePrettyUrl' => true, 'rules' => ['POST /oauth2/<action:\\w+>' => 'oauth2/default/<action>', ['class' => 'yii\\rest\\UrlRule', 'controller' => 'v1/product', 'extraPatterns' => ['GET custom' => 'custom', 'GET protected' => 'protected']]]], 'request' => ['parsers' => ['application/json' => 'yii\\web\\JsonParser']], 'response' => ['class' => 'yii\\web\\Response', 'formatters' => [yii\web\Response::FORMAT_HTML => '\\api\\components\\HtmlResponseFormatter'], 'on beforeSend' => function (\yii\base\Event $event) { /** @var \yii\web\Response $response */ $response = $event->sender; // catch situation, when no controller hasn't been loaded // so no filter wasn't loaded too. Need to understand in which format return result if (empty(Yii::$app->controller)) { $content_neg = new \yii\filters\ContentNegotiator(); $content_neg->response = $response; $content_neg->formats = Yii::$app->params['formats']; $content_neg->negotiate(); } if ($response->data !== null && Yii::$app->request->get('suppress_response_code')) { $response->data = ['success' => $response->isSuccessful, 'data' => $response->data]; $response->statusCode = 200; } }], 'user' => ['identityClass' => 'api\\models\\User', 'loginUrl' => null, 'enableSession' => false]], 'params' => []];