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

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

jardisadapter/http
==================

PSR-18 HTTP client with cURL transport, Bearer and Basic auth, minimal footprint

v1.0.0(1mo ago)052↓85%1MITPHPPHP &gt;=8.2CI passing

Since Jun 1Pushed 2w agoCompare

[ Source](https://github.com/jardisAdapter/http)[ Packagist](https://packagist.org/packages/jardisadapter/http)[ Docs](https://docs.jardis.io/en/adapter/http)[ RSS](/packages/jardisadapter-http/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (4)Dependencies (6)Versions (3)Used By (1)

Jardis HTTP Client
==================

[](#jardis-http-client)

[![Build Status](https://github.com/jardisAdapter/http/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisAdapter/http/actions/workflows/ci.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/a68b290dcc313d698dc138a1111aa83eee2f143605449d7e8b5416ea6f88558f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3737374242342e737667)](https://www.php.net/)[![PHPStan Level](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](phpstan.neon)[![PSR-12](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](phpcs.xml)[![PSR-18](https://camo.githubusercontent.com/440f01108aa5c5d1e7ad2d85ae34000c9677d70beab67ff3ea52b75a112341e5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f485454502d5053522d2d31382d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-18/)

> Part of **[Jardis](https://jardis.io)** — the Domain-Driven Design platform for PHP. You model your domain; Jardis generates the production-ready hexagonal code (DTOs, Command/Query handlers, repositories, persistence). This package is part of the open-source foundation that generated code runs on.

**HTTP requests without overhead.** A lean PSR-18 HTTP client for PHP built on cURL — designed for applications that call external APIs, send webhooks, or integrate services. No framework, no middleware stack, no dependency bloat. Just what you need.

---

Why This Client?
----------------

[](#why-this-client)

- **Two classes to learn** — `HttpClient` + `ClientConfig`. Includes its own PSR-7/PSR-17 implementation — zero external dependencies
- **Handler pipeline** — each concern is its own invokable, orchestrated internally by the client
- **Retry with backoff** — automatic retry on 5xx and network errors
- **PSR-18 compatible** — works with any PSR-18-capable code
- **96% test coverage** — integration tests against real HTTP requests, not mocks

---

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

[](#installation)

```
composer require jardisadapter/http
```

---

Quick Start
-----------

[](#quick-start)

### GET Request

[](#get-request)

```
use JardisAdapter\Http\HttpClient;
use JardisAdapter\Http\Config\ClientConfig;

use JardisAdapter\Http\Message\Psr17Factory;

$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
    baseUrl: 'https://api.example.com/v2',
));

$response = $client->get('/users');
$data = json_decode((string) $response->getBody(), true);
```

### POST with JSON Body

[](#post-with-json-body)

```
$response = $client->post('/users', [
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);
```

### PUT, PATCH, DELETE

[](#put-patch-delete)

```
$client->put('/users/1', ['name' => 'Jane Doe']);
$client->patch('/users/1', ['status' => 'active']);
$client->delete('/users/1');
```

### Custom Headers per Request

[](#custom-headers-per-request)

```
$response = $client->get('/reports', ['Accept' => 'text/csv']);
$response = $client->post('/import', $data, ['X-Request-Id' => 'abc-123']);
```

### Fully Configured

[](#fully-configured)

```
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
    baseUrl: 'https://api.example.com/v2',
    timeout: 10,
    connectTimeout: 5,
    verifySsl: true,
    defaultHeaders: ['Accept' => 'application/json'],
    bearerToken: 'eyJhbGciOiJI...',
    maxRetries: 3,
    retryDelayMs: 200,
));

$response = $client->get('/users');
$response = $client->post('/orders', ['product' => 'Widget', 'quantity' => 3]);
```

---

Authentication
--------------

[](#authentication)

### Bearer Token

[](#bearer-token)

```
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
    bearerToken: 'eyJhbGciOiJI...',
));
// Authorization: Bearer eyJhbGciOiJI... is set automatically
```

### Basic Auth

[](#basic-auth)

```
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
    basicUser: 'api-user',
    basicPassword: 'secret',
));
```

---

Retry
-----

[](#retry)

```
$psr17 = new Psr17Factory();
$client = new HttpClient($psr17, $psr17, $psr17, $psr17, new ClientConfig(
    maxRetries: 3,          // Up to 3 retries on 5xx
    retryDelayMs: 200,      // Exponential backoff: 200ms, 400ms, 800ms
));
```

Automatically retries on HTTP 5xx and transport errors (`HttpClientException`, which covers both `NetworkException` and `RequestException`). No retry on 4xx — those are caller errors.

---

Error Handling
--------------

[](#error-handling)

The client does **not throw exceptions on HTTP 4xx/5xx** — those are valid responses. Exceptions are only thrown for actual errors:

ExceptionWhen`NetworkException`DNS failure, connection refused, timeout`RequestException`Invalid request (malformed URI)```
use JardisAdapter\Http\Exception\NetworkException;

try {
    $response = $client->get('/users');
} catch (NetworkException $e) {
    // Network problem — retry was already active (if configured)
}

if ($response->getStatusCode() >= 400) {
    // Handle HTTP errors yourself
}
```

---

PSR-18 Compatible
-----------------

[](#psr-18-compatible)

The client implements `Psr\Http\Client\ClientInterface`. For full control over the request, use `sendRequest()`:

```
use JardisAdapter\Http\Message\Psr17Factory;

$factory = new Psr17Factory();
$request = $factory->createRequest('OPTIONS', 'https://api.example.com');
$response = $client->sendRequest($request);
```

---

Architecture
------------

[](#architecture)

The user only sees `HttpClient` + `ClientConfig`. Internally, the client orchestrates a pipeline of invokable handlers — built from the config:

```
HttpClient (Orchestrator)
  │
  │  Convenience methods: get(), post(), put(), patch(), delete(), head()
  │  └── internally create PSR-7 requests
  │
  │  Transformers (Request → Request, built from config):
  │  ├── BaseUrl           resolve relative URLs
  │  ├── DefaultHeaders    set default headers
  │  ├── BearerAuth        add bearer token
  │  └── BasicAuth         add basic auth
  │
  │  Transport (Request → Response, built from config):
  │  ├── CurlTransport     cURL-based transport
  │  └── Retry             wraps transport with exponential backoff
  │
  ▼
  sendRequest():
    foreach transformer → $request = $transform($request)
    return $transport($request, $config)

```

Each handler is an **invokable object** (`__invoke`) — independently testable, replaceable, composable. Only what is configured gets instantiated.

### Custom Transport

[](#custom-transport)

The transport is a closure — replaceable without changing the client:

```
$psr17 = new Psr17Factory();
$client = new HttpClient(
    requestFactory: $psr17,
    streamFactory: $psr17,
    responseFactory: $psr17,
    uriFactory: $psr17,
    config: new ClientConfig(),
    transport: function (RequestInterface $request, ClientConfig $config) use ($psr17) {
        return $psr17->createResponse(200)
            ->withBody($psr17->createStream('{"mocked": true}'));
    },
);
```

---

Jardis Foundation Integration
-----------------------------

[](#jardis-foundation-integration)

In a Jardis DDD project, the client is automatically configured via ENV:

```
HTTP_BASE_URL=https://api.example.com
HTTP_TIMEOUT=30
HTTP_CONNECT_TIMEOUT=10
HTTP_VERIFY_SSL=true
HTTP_BEARER_TOKEN=eyJhbGciOiJI...
HTTP_MAX_RETRIES=3
HTTP_RETRY_DELAY_MS=200
```

The `HttpClientHandler` in `JardisApp` builds the client and registers it in the ServiceRegistry. Your domain code receives `ClientInterface` via injection — without ever importing `HttpClient` directly.

---

Development
-----------

[](#development)

```
cp .env.example .env    # One-time setup
make install             # Install dependencies
make phpunit             # Run tests
make phpstan             # Static analysis (Level 8)
make phpcs               # Coding standards (PSR-12)
```

---

Documentation
-------------

[](#documentation)

Full documentation, guides, and API reference:

**[docs.jardis.io/en/adapter/http](https://docs.jardis.io/en/adapter/http)**

---

License
-------

[](#license)

[MIT License](LICENSE.md) — free for any use, including commercial.

AI-Assisted Development
-----------------------

[](#ai-assisted-development)

This package ships with a skill for Claude Code, Cursor, Continue, and Aider. Install it in your consuming project:

```
composer require --dev jardis/dev-skills
```

More details:

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

30d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e07a1b668e9e01ee6d1b85de7b3be1c2513f68aae9494b2011d1592104d5daa0?d=identicon)[jardis](/maintainers/jardis)

---

Top Contributors

[![Headgent](https://avatars.githubusercontent.com/u/245725954?v=4)](https://github.com/Headgent "Headgent (7 commits)")

---

Tags

curldomain-driven-designhttp-clientjardisphppsr-18retryhttppsr-7clientcurlpsr-18Domain Driven DesignHeadgentjardis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B3.9k](/packages/guzzlehttp-psr7)[guzzlehttp/guzzle

Guzzle is a PHP HTTP client library

23.5k1.0B35.0k](/packages/guzzlehttp-guzzle)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

185702.8k42](/packages/laudis-neo4j-php-client)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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