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

ActiveNixphp-plugin[HTTP &amp; Networking](/categories/http)

nixphp/client
=============

NixPHP Client Plugin to make simple http requests.

v0.1.1(5mo ago)034MITPHPPHP &gt;=8.3CI passing

Since Dec 9Pushed 5mo agoCompare

[ Source](https://github.com/nixphp/client)[ Packagist](https://packagist.org/packages/nixphp/client)[ RSS](/packages/nixphp-client/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (5)Used By (0)

```

![Logo](https://nixphp.github.io/docs/assets/nixphp-logo-small-square.png)

[![NixPHP Client Plugin](https://github.com/nixphp/client/actions/workflows/php.yml/badge.svg)](https://github.com/nixphp/client/actions/workflows/php.yml)

[← Back to NixPHP](https://github.com/nixphp/framework)

---

# nixphp/client

> **Lightweight PSR-18 HTTP client — pragmatic, robust, and framework-friendly.**

This plugin provides a small and dependency-free implementation of
`Psr\Http\Client\ClientInterface`, designed for **internal APIs, integrations,
and infrastructure code** inside NixPHP applications.

It focuses on **correctness, stability, and testability** rather than feature bloat.

> 🧩 Official NixPHP plugin
> Minimal surface area, explicit behavior, no hidden magic.

---

## Features

* Implements `Psr\Http\Client\ClientInterface`
* Transport-based architecture (cURL + Streams)
* Automatic fallback when a transport is unavailable
* Robust TLS handling (CA bundle detection, retries on transient errors)
* Configurable HTTP protocol version

---

## Transport Architecture

The client delegates all network I/O to **transports**.

### Included transports

| Transport | Purpose |
|---------|--------|
| `CurlTransport` | Preferred, robust, supports HTTP/2 and modern TLS |
| `StreamTransport` | Fallback using native PHP streams |

The client automatically selects the **first available transport** at runtime.
No configuration required.

This design keeps the client:
- simple
- testable
- extensible (custom transports can be injected)

---

## Installation

```bash
composer require nixphp/client
```

The plugin is autoloaded automatically.

---

Usage
-----

[](#usage)

### Send a PSR-7 request

[](#send-a-psr-7-request)

```
use Nyholm\Psr7\Request;

$request  = new Request('GET', 'https://example.com/api');
$response = client()->sendRequest($request);

echo $response->getStatusCode();
echo (string) $response->getBody();
```

The client always returns a standard PSR-7 `ResponseInterface`. No automatic JSON parsing or response mutation is performed.

---

Configuration
-------------

[](#configuration)

All options live under the `client` key.

```
// app/config.php
return [
    'client' => [

        // TLS verification
        'ssl_verify' => true,

        // Retry behavior for transient network/TLS errors
        'retries' => 1,
        'retry_delay_ms' => 150,

        // Timeouts (seconds)
        'timeout' => 20,
        'connect_timeout' => 8,

        // HTTP protocol version
        // auto | 1.1 | 2
        'http_version' => 'auto',

        // Optional explicit CA bundle path
        // 'cacert' => '/path/to/ca-bundle.crt',
    ],
];
```

### Notes

[](#notes)

- `http_version = auto` lets cURL negotiate the best protocol (usually HTTP/2).
- PHP streams only support HTTP/1.0 and HTTP/1.1 — HTTP/2 requires cURL.
- CA bundles are auto-detected on common Linux distributions.

---

Testing
-------

[](#testing)

The transport abstraction allows **pure unit tests** without real HTTP calls.

```
$transport = new MockTransport();
$transport->pushResponse('ok', ['HTTP/1.1 200 OK']);

$client = new Client([$transport]);
$response = $client->sendRequest($request);
```

This makes the client:

- fast to test
- deterministic
- independent of network state

---

Design Principles
-----------------

[](#design-principles)

- The client does **not** parse or decode JSON automatically
- Response bodies are returned exactly as received
- Protocol and transport decisions are explicit
- No global state, no side effects, no surprises

This keeps the client predictable and PSR-18-aligned.

---

Requirements
------------

[](#requirements)

- PHP ≥ 8.2
- `nixphp/framework` &gt;= 0.1.0
- `nyholm/psr7` &gt;= 1.0 (used for PSR-7 implementation)

---

📄 License
---------

[](#-license)

MIT License

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance70

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

Every ~35 days

Total

2

Last Release

170d ago

### Community

Maintainers

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

---

Top Contributors

[![FloKnapp](https://avatars.githubusercontent.com/u/3774820?v=4)](https://github.com/FloKnapp "FloKnapp (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M83](/packages/mollie-mollie-api-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[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)[laudis/neo4j-php-client

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

185702.8k43](/packages/laudis-neo4j-php-client)[claude-php/claude-php-sdk

A universal, framework-agnostic PHP SDK for the Anthropic Claude API with PSR compliance

14650.3k2](/packages/claude-php-claude-php-sdk)[internal/dload

Downloads binaries.

102211.4k19](/packages/internal-dload)

PHPackages © 2026

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