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\Transport;
use Innmind\Time\Clock;
use Innmind\Http\Request;

$fulfill = Transport::curl(Clock::live());

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

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

$fulfill = Transport::curl(Clock::live())->map(
    static fn($config) => $config->limitConcurrencyTo(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\Transport;
use Psr\Log\LoggerInterface;

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

$fulfill(/* your request */);

use Innmind\HttpTransport\Transport;
use Innmind\Time\Halt;

$fulfill = Transport::exponentialBackoff(
    /* an instance of Transport */,
    Halt::new(),
);

$fulfill(/* your request */);

use Innmind\HttpTransport\Transport;
use Innmind\Time\{
    Clock,
    Period,
};

$fulfill = Transport::circuitBreaker(
    /* an instance of Transport */,
    Clock::live(),
    Period::minute(10),
);

$fulfill(/* your request */);

use Innmind\HttpTransport\Transport;

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

$fulfill(/* your request */);