PHPackages                             innmind/http-transport - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. innmind/http-transport

ActiveLibrary[HTTP &amp; Networking](/categories/http)

innmind/http-transport
======================

Library to fulfill http resquest

9.0.0(3mo ago)199.6k↓27.3%1[3 issues](https://github.com/Innmind/HttpTransport/issues)6MITPHPPHP ~8.4CI passing

Since Nov 15Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Innmind/HttpTransport)[ Packagist](https://packagist.org/packages/innmind/http-transport)[ Docs](http://github.com/Innmind/HttpTransport)[ RSS](/packages/innmind-http-transport/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (40)Used By (6)

HttpTransport
=============

[](#httptransport)

[![CI](https://github.com/Innmind/HttpTransport/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Innmind/HttpTransport/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/9964e528bb8f1c91555c2f25f9f406084ebcfb4c658c8af8d2b6812f3777f848/68747470733a2f2f636f6465636f762e696f2f67682f696e6e6d696e642f687474707472616e73706f72742f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/innmind/httptransport)[![Type Coverage](https://camo.githubusercontent.com/7ad341db2a07d3f287b0db574dd0db32f38b6307d2b96a240458dba94bc3ba89/68747470733a2f2f73686570686572642e6465762f6769746875622f696e6e6d696e642f687474707472616e73706f72742f636f7665726167652e737667)](https://shepherd.dev/github/innmind/httptransport)

This library allows you to send [http](https://packagist.org/packages/innmind/http) request.

Important

to use this library correctly you must use [`vimeo/psalm`](https://packagist.org/packages/vimeo/psalm).

Installation
------------

[](#installation)

```
composer require innmind/http-transport
```

Usage
-----

[](#usage)

Send a request:

```
use Innmind\HttpTransport\Transport;
use Innmind\Time\Clock;
use Innmind\Http\Request;

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

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

`2xx` responses will be on the right side of `$either`, all errors and other kinds of responses will be on the left side.

Important

you must call `match` to the returned `Either` otherwise the request will not be sent, but you can still call other methods on the `Either` before calling `match`.

Concurrency
-----------

[](#concurrency)

By default there is no limit of concurrency for the `Curl` transport. But if you call many requests before unwrapping the results you may want to configure the max concurrency like below.

```
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
```

Let's say you have `100` urls to fetch, there will never be more than `5` requests being done in parallel.

Log the request
---------------

[](#log-the-request)

You can easily log all your requests like so:

```
use Innmind\HttpTransport\Transport;
use Psr\Log\LoggerInterface;

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

$fulfill(/* your request */);
```

Here a message is logged before the request is sent and another one once it's sent.

Exponential Backoff
-------------------

[](#exponential-backoff)

Sometimes when calling an external API it may not be available due to heavy load, in such case you could retry the http call after a certain amount of time leaving time for the API to recover. You can apply this pattern like so:

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

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

$fulfill(/* your request */);
```

By default it will retry 5 times the request if the server is unavailable, following the given periods (in milliseconds) between each call: `100`, `271`, `738`, `2008` and `5459`.

Circuit breaker
---------------

[](#circuit-breaker)

When a call to a certain domain fails you may want to all further calls to that domain to fail immediately as you know it means the host is down. Such pattern is called a circuit breaker.

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

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

$fulfill(/* your request */);
```

This code will *open the circuit* for a given domain for 10 minutes in case a call results in a server error, after this delay the transport will let new request through as if nothing happened.

Follow redirections
-------------------

[](#follow-redirections)

By default the transports do not follow redirections to give you full control on what to do. But you can wrap your transport with `FollowRedirections` like this:

```
use Innmind\HttpTransport\Transport;

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

$fulfill(/* your request */);
```

To avoid infinite loops it will follow up to 5 consecutive redirections.

Important

as defined in the [rfc](https://datatracker.ietf.org/doc/html/rfc2616/#section-10.3.2), requests with methods other than `GET` and `HEAD` that results in redirection with the codes `301`, `302`, `307` and `308` will **NOT** be redirected. It will be up to you to implement the redirection as you need to make sure such redirection is safe.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance60

Regular maintenance activity

Popularity34

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~175 days

Total

37

Last Release

106d ago

Major Versions

4.1.0 → 5.0.02020-01-16

5.2.0 → 6.0.02022-03-13

6.6.0 → 7.0.02023-10-22

7.3.0 → 8.0.02025-05-10

8.1.0 → 9.0.02026-02-01

PHP version history (8 changes)1.0.0PHP ~7.0

2.0.0PHP ~7.1

3.1.0PHP ~7.2

5.0.0PHP ~7.4

5.2.0PHP ~7.4|~8.0

6.0.0PHP ~8.1

6.6.0PHP ~8.2

9.0.0PHP ~8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/851425?v=4)[Baptiste Langlade](/maintainers/Baptouuuu)[@Baptouuuu](https://github.com/Baptouuuu)

---

Top Contributors

[![Baptouuuu](https://avatars.githubusercontent.com/u/851425?v=4)](https://github.com/Baptouuuu "Baptouuuu (266 commits)")[![vdechenaux](https://avatars.githubusercontent.com/u/1501825?v=4)](https://github.com/vdechenaux "vdechenaux (1 commits)")

---

Tags

httpclient

### Embed Badge

![Health badge](/badges/innmind-http-transport/health.svg)

```
[![Health](https://phpackages.com/badges/innmind-http-transport/health.svg)](https://phpackages.com/packages/innmind-http-transport)
```

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[simpod/clickhouse-client

PHP ClickHouse Client

19116.7k](/packages/simpod-clickhouse-client)[m6web/guzzle-http-bundle

Symfony bundle on top of Guzzle

17511.5k2](/packages/m6web-guzzle-http-bundle)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
