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(4mo ago)034MITPHPPHP &gt;=8.3CI passing

Since Dec 9Pushed 4mo agoCompare

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

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

35

—

LowBetter than 80% of packages

Maintenance77

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

125d 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

[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laudis/neo4j-php-client

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

184616.9k31](/packages/laudis-neo4j-php-client)[php-http/socket-client

Socket client for PHP-HTTP

812.5M45](/packages/php-http-socket-client)[elastic/transport

HTTP transport PHP library for Elastic products

2020.6M7](/packages/elastic-transport)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[juststeveking/php-sdk

A framework for building SDKs in PHP.

21872.0k2](/packages/juststeveking-php-sdk)

PHPackages © 2026

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