PHP code example of fast-forward / http-client

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

    

fast-forward / http-client example snippets




declare(strict_types=1);

use FastForward\Http\Client\ServiceProvider\HttpClientServiceProvider;
use FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;

use function FastForward\Container\container;

$container = container(
    new HttpMessageFactoryServiceProvider(),
    new HttpClientServiceProvider(),
);

/** @var RequestFactoryInterface $requestFactory */
$requestFactory = $container->get(RequestFactoryInterface::class);
$request = $requestFactory->createRequest('GET', 'https://example.com');

/** @var ClientInterface $client */
$client = $container->get(ClientInterface::class);
$response = $client->sendRequest($request);

$statusCode = $response->getStatusCode();
$body = (string) $response->getBody();