PHP code example of innmind / http-transport

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

    

innmind / http-transport example snippets


use Innmind\HttpTransport\Curl;
use Innmind\TimeContinuum\Earth\Clock;
use Innmind\Http\Request;

$fulfill = Curl::of(new Clock);

$either = $fulfill(
    Request::of(/* initialize your request */),
);

use Innmind\HttpTransport\Curl;
use Innmind\Http\{
    Request,
    Response,
    Method,
    ProtocolVersion,
};
use Innmind\Url\Url;
use Innmind\Immutable\Sequence;

$fulfill = Curl::of(new Clock)->maxConcurrency(5);
$responses = Sequence::of(
    'https://github.com/user/repo-a',
    'https://github.com/user/repo-b',
    'https://github.com/user/repo-c',
    // etc...
)
    ->map(static fn($url) => Request::of(
        Url::of($url),
        Method::get,
        ProtocolVersion::v20,
    ))
    ->map($fulfill)
    ->flatMap(static fn($either) => $either->match(
        static fn($success) => Sequence::of($success->response()),
        static fn() => Sequence::of(), // discard errors
    ))
    ->toList();
$responses; // list<Response>

use Innmind\HttpTransport\Logger
use Psr\Log\LoggerInterface;

$fulfill = Logger::psr(/* an instance of Transport */, /* an instance of LoggerInterface */)

$fulfill(/* your request */);

use Innmind\HttpTransport\ExponentialBackoff;
use Innmind\TimeWarp\Halt\Usleep;

$fulfill = ExponentialBackoff::of(
    /* an instance of Transport */,
    new Usleep,
);

$fulfill(/* your request */);

use Innmind\HttpTransport\CircuitBreaker;
use Innmind\TimeContinuum\Earth\{
    Clock,
    Period\Minute,
};

$fulfill = CircuitBreaker::of(
    /* an instance of CircuitBreaker */,
    new Clock,
    new Minute(10),
);

$fulfill(/* your request */);

use Innmind\HttpTransport\FollowRedirections;

$fulfill = FollowRedirections::of(/* an instance of Transport */);

$fulfill(/* your request */);