PHP code example of athena-oss / php-fluent-http-client

1. Go to this page and download the library: Download athena-oss/php-fluent-http-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

athena-oss / php-fluent-http-client example snippets


$responseJson = (new HttpClient())->get('http://example.com')
            ->withHeader('name', 'value')
            ->withProxy('http://myproxy.com', 3128)
            ->then()
            ->assertThat()
            ->headerValueIsEqual('expected_header', 'expected_value')
            ->responseIsJson()
            ->statusCodeIs(200)
            ->retrieve()
            ->fromJson();

$responseString = (new HttpClient())->put('http://example.com')
            ->withUserAgent('my_user_agent_string')
            ->withDigestAuth('myusername', 'mypassword')
            ->withProxy('http://myproxy', 1234)
            ->withBody('my content', 'my content type')
            ->then()
            ->assertThat()
            ->statusCodeIs(201)
            ->retrieve()
            ->fromString();