Official HTTP client for Yii 2 released

    The Yii team has released the official HTTP client extension. It was written almost entirely by Pavel Klimov. Until recently, it was not tagged as a release due to incompatibility with the PSR-7, although it has already been used a lot. After much discussion, it was decided to release without PSR-7. They may return to him in 2.1.x.


    Making an HTTP request looks like this:


    use yii\httpclient\Client;
    $client = new Client();
    $response = $client->createRequest()
        ->setMethod('post')
        ->setUrl('http://example.com/api/1.0/users')
        ->setData(['name' => 'John Doe', 'email' => 'johndoe@domain.com'])
        ->send();
    if ($response->isOk) {
        $newUserId = $response->data['id'];
    }

    https://github.com/yiisoft/yii2-httpclient


    Also popular now: