PHPackages                             efabrica/http-client - 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. efabrica/http-client

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

efabrica/http-client
====================

Wraps Symfony HTTP client, adds named arguments.

0.5.0(6mo ago)035.4k↓50.7%3MITPHPPHP ^8.4CI passing

Since Mar 27Pushed 6mo ago3 watchersCompare

[ Source](https://github.com/efabrica-team/http-client)[ Packagist](https://packagist.org/packages/efabrica/http-client)[ RSS](/packages/efabrica-http-client/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (7)Versions (20)Used By (0)

eFabrica HTTP Client
====================

[](#efabrica-http-client)

**efabrica/http-client** is a PHP package that provides a simple and efficient HTTP client based on Symfony's HttpClient component. It adds named arguments in constructor and methods, and provides a more statically analysable API for making HTTP requests. If Symfony changes the HttpClient component, this package's effort will be to avoid breaking changes.

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

[](#installation)

You can install the package using Composer. Run the following command in your project's root directory:

```
composer require efabrica/http-client
```

> ⚠️ PHP &gt;=8.1 is required.

Usage
-----

[](#usage)

### Creating an instance

[](#creating-an-instance)

To create an instance of the `HttpClient` class, use the `create` method. This method allows you to configure various options for the HTTP client, such as base URL, headers, authentication, and more.

```
use Efabrica\HttpClient\HttpClient;

// Create an instance with default options
$http = new HttpClient();

// Create an instance with custom options
$http = new HttpClient(
    baseUri: 'https://api.example.com',
    authBearer: 'your-access-token',
    timeout: 10.0,
    // ... other options
);
```

### Making Requests

[](#making-requests)

The `HttpClient` class provides methods for making different types of HTTP requests: GET, POST, PUT, PATCH, DELETE.

```
use Efabrica\HttpClient\HttpClient;

$http = new HttpClient('https://api.example.com', 'example_llt');

// Send a GET request
$response = $http->get('/resource', ['offset' => 0, 'limit' => 10]);

// Send a POST request with JSON payload
$response = $http->post('/resource', json: ['key' => 'value']);

// Send a POST request with FormData payload
$response = $http->post('/resource', body: ['key' => 'value']);

// Send a PUT request
$response = $http->put('https://api.example2.com/resource', ['email' => 'admin@example.com']);

// ... other request methods
```

### Handling Asynchronous Responses

[](#handling-asynchronous-responses)

The `HttpClient` class returns `HttpResponse` object which implements Symfony's `ResponseInterface`. This allows you to work with responses asynchronously without blocking until their methods are called.

```
use Efabrica\HttpClient\HttpClient;

$http = new HttpClient();

// Send an asynchronous request (does not block)
$response = $http->get('https://api.example.com/resource');

// Access response asynchronously
// > Exceptions are thrown when the response is read
$response->getHttpCode(); // int|null       (does not block, returns null if response code is not available yet)
$response->getStatusCode(); // int          (blocks until response headers are available)
$response->getResponseHeaders(); // array   (blocks until response headers are available)
$response->getHeaders(); // array           (blocks until response headers are available)
$response->getContent(); // string          (blocks until response body is available)
$response->toArray(); // JSON body as array (blocks until response body is available)
```

### Streaming Responses

[](#streaming-responses)

You can use the `stream` method to yield responses chunk by chunk as they complete.

```
use Efabrica\HttpClient\HttpClient;

$http = new HttpClient();

// Send multiple requests and stream responses
$responses = [
    $http->get('https://api.example.com/resource1'),
    $http->get('https://api.example.com/resource2'),
    // ... add more requests
];

$stream = $http->stream($responses);

foreach ($stream as $response) {
    // Process each response asynchronously
}
```

### Adding Decorators

[](#adding-decorators)

You can enhance the functionality of the `HttpClient` by adding decorators. Decorators can modify or extend the behavior of the underlying HTTP client.

```
use Efabrica\HttpClient\HttpClient;
use Symfony\Component\HttpClient\Decorator\CachedHttpClient;

$http = new HttpClient();

// Add a decorator to the HTTP client
$http->setClient(new BlackfiredHttpClient($http->getClient(), $blackfire));

// Create a new instance with an additional decorator
$blackfiredClient = $http->withClient(new BlackfiredHttpClient($http->getClient(), $blackfire));
```

### Updating Options

[](#updating-options)

```
use Efabrica\HttpClient\HttpClient;

// Create an instance with default options
$http = new HttpClient();

// Create a new instance with updated options
$newHttp = $http->withOptions(baseUrl: 'https://api.new-example.com', /* ... */);

// Now $newHttp is a new instance of HttpClient with the updated options
```

This example shows how to create a new instance of `HttpClient` with updated options using the `withOptions` method. The original `HttpClient` instance remains unchanged.

### Tracy integration

[](#tracy-integration)

```
# config.neon
tracy:
  blueScreen:
    - Efabrica\HttpClient\Tracy\HttpResponseBluescreen::renderException
  bar:
    - Efabrica\HttpClient\Tracy\HttpPanel()
```

Contributions
-------------

[](#contributions)

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance66

Regular maintenance activity

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~45 days

Recently: every ~100 days

Total

15

Last Release

196d ago

PHP version history (4 changes)0.1.0PHP &gt;=8.1

0.2.0PHP ^8.2

0.2.1PHP ^8.1

0.5.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/25289c62a88df1c404543693ba52e44748dbce486bcfab91fc8c5931a6bb38e1?d=identicon)[dev-efabrica](/maintainers/dev-efabrica)

---

Top Contributors

[![riki137](https://avatars.githubusercontent.com/u/1223388?v=4)](https://github.com/riki137 "riki137 (24 commits)")[![lulco](https://avatars.githubusercontent.com/u/9377319?v=4)](https://github.com/lulco "lulco (4 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/efabrica-http-client/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M572](/packages/shopware-core)[contao/manager-bundle

Provides the Contao Managed Edition

181.3M74](/packages/contao-manager-bundle)[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

10244.2k5](/packages/bitrix24-b24phpsdk)

PHPackages © 2026

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