PHP code example of free-elephants / static-http-client

1. Go to this page and download the library: Download free-elephants/static-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/ */

    

free-elephants / static-http-client example snippets


public function test()
{
    $stubbedHttpClient = new \FreeElephants\StaticHttpClient\StaticHttpClient(
        $responseFactory, 
        new \FreeElephants\StaticHttpClient\PathResolver\PathBuilderBasedResolver(
            new \FreeElephants\StaticHttpClient\PathBuilder\Composite(
                new \FreeElephants\StaticHttpClient\PathBuilder\PrependBasePath(__DIR__),
                new \FreeElephants\StaticHttpClient\PathBuilder\PrependHostnameAsDirectory(),
                new \FreeElephants\StaticHttpClient\PathBuilder\AppendRequestPath(),
                new \FreeElephants\StaticHttpClient\PathBuilder\AppendDefaultFileExtension('.json'),
            ) 
        )
    );
    
    $response = $stubbedHttpClient->sendRequest(new \Nyholm\Psr7\Request('GET', 'https://example.com/foo')); // resolved as __DIR__ . '/example.com/foo.json'  
}