Class yii\httpclient\JsonFormatter

Inheritanceyii\httpclient\JsonFormatter » yii\base\BaseObject
Available since extension's version2.0
Source Code

JsonFormatter formats HTTP message as JSON.

Public Properties

Hide inherited properties

Property Type Description Defined By
$encodeOptions integer The encoding options. yii\httpclient\JsonFormatter

Public Methods

Hide inherited methods

Method Description Defined By
format() Formats given HTTP request message. yii\httpclient\JsonFormatter

Property Details

Hide inherited properties

$encodeOptions public property

The encoding options. For more details please refer to

Method Details

Hide inherited methods

format() public method

Formats given HTTP request message.

public yii\httpclient\Request format ( yii\httpclient\Request $request )
$request yii\httpclient\Request

HTTP request instance.

return yii\httpclient\Request

Formatted request.

                public function format(Request $request)
    $request->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
    if (($data = $request->getData()) !== null) {
        $request->setContent(Json::encode($request->getData(), $this->encodeOptions));
    return $request;