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

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

osirisgate/http-client
======================

Provides powerful and flexible methods to fetch HTTP resources synchronously or asynchronously.

1.0.0(11mo ago)0191MITPHPPHP &gt;=8.2

Since Jun 4Pushed 11mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (8)Versions (2)Used By (1)

🌐 Osirisgate HTTP Client
========================

[](#-osirisgate-http-client)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/337c77af623b2c89c0dee0d532c1ca73390e5e9f06f06217a72493ad0cdfab4d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d382e322d3838393242462e737667)](https://www.php.net/releases/8.2/)

> Lightweight, elegant HTTP client built with modern PHP. Provides an expressive and extensible wrapper to perform REST API calls using clean, typed interfaces. Aligned with Osirisgate Core standards.

---

📦 Installation
--------------

[](#-installation)

```
composer require osirisgate/http-client
```

✅ Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- [osirisgate/core](https://github.com/osirisgate/core/)

✨ Features
----------

[](#-features)

- Simple and expressive methods for HTTP verbs: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`
- Structured exception system implementing `ExceptionInterface`
- Response abstraction through `ResponseInterface`
- Optional support for:
    - Query parameters (`filters`)
    - Custom headers
    - Low-level request options

🧑‍💻 How to use it ?
-------------------

[](#‍-how-to-use-it-)

### ✅ Send a GET request

[](#-send-a-get-request)

```
use Osirisgate\Component\HttpClient\Request\Http;

$response = Http::get('https://jsonplaceholder.typicode.com/posts');
$data = $response->toArray();
```

### 📌 With query parameters

[](#-with-query-parameters)

```
$response = Http::get(
    'https://jsonplaceholder.typicode.com/comments',
    filters: ['postId' => 1]
);

$comments = $response->toArray();
```

### ✍️ Create a resource (POST)

[](#️-create-a-resource-post)

```
$response = Http::post(
    'https://jsonplaceholder.typicode.com/posts',
    payload: [
        'title' => 'foo',
        'body' => 'bar',
        'userId' => 1
    ]
);
```

### 🔁 Update a resource (PUT / PATCH)

[](#-update-a-resource-put--patch)

```
// PUT (Full update)
$response = Http::put('https://jsonplaceholder.typicode.com/posts/1', payload: [
    'id' => 1,
    'title' => 'new title',
    'body' => 'updated content',
    'userId' => 1
]);

// PATCH (Partial update)
$response = Http::patch('https://jsonplaceholder.typicode.com/posts/1', payload: [
    'title' => 'patched title'
]);
```

### ❌ Delete a resource

[](#-delete-a-resource)

```
$response = Http::delete('https://jsonplaceholder.typicode.com/posts/1');
```

⚙️ Advanced Configuration
-------------------------

[](#️-advanced-configuration)

### 🧾 Custom headers

[](#-custom-headers)

```
$response = Http::get(
    'https://api.example.com/data',
    headers: [
        'Authorization' => 'Bearer TOKEN',
        'X-Custom-Header' => 'value'
    ]
);
```

### 🛠 Request options

[](#-request-options)

The options parameter allows for fine-grained control over the underlying HTTP request. Here's a detailed overview of the available options:

- `timeout`: int (default: 30) - Sets the timeout of the request in seconds.
- `max_redirects`: int (default: 20) - Specifies the maximum number of redirects to follow.
- `http_version`: string|null (default: null) - Sets the HTTP protocol version (e.g., '1.1', '2.0').
- `base_uri`: string|null (default: null) - Sets a base URI for resolving relative URLs.
- `headers`: array (default: \[\]) - An associative array of HTTP headers.
- `auth_basic`: array|null (default: null) - Enables HTTP basic authentication with \['username', 'password'\].
- `auth_bearer`: string|null (default: null) - Sets the Authorization header with a bearer token.
- `auth_ntlm`: array|null (default: null) - Enables NTLM authentication with \['username', 'password'\].
- `query`: array (default: \[\]) - Associative array of query parameters to append to the URI.
- `body`: resource|string|null (default: null) - The raw request body.
- `json`: mixed|null (default: null) - If provided, will be JSON-encoded and used as the request body with the correct Content-Type.
- `user_data`: mixed|null (default: null) - Arbitrary user-defined data associated with the request.
- `bindto`: string|null (default: null) - Binds to a specific network interface or local port.
- `proxy`: string|null (default: null) - URI of a proxy server to use.
- `no_proxy`: string|null (default: null) - Comma-separated list of hostnames to bypass the proxy.
- `verify_peer`: bool (default: true) - Whether to verify the peer's SSL certificate. Set to false with caution in production.
- `verify_host`: bool (default: true) - Whether to verify the hostname against the SSL certificate.
- `cafile`: string|null (default: null) - Path to a custom CA bundle file for SSL verification.
- `capath`: string|null (default: null) - Path to a directory containing CA certificates.
- `local_cert`: string|null (default: null) - Path to a client-side certificate file for client authentication.
- `local_pk`: string|null (default: null) - Path to the private key file associated with local\_cert.
- `passphrase`: string|null (default: null) - Passphrase for the private key.
- `ciphers`: string|null (default: null) - List of SSL/TLS ciphers to use.
- `peer_fingerprint`: array|null (default: null) - Verify the peer's certificate by its fingerprint (e.g., \['sha256' =&gt; '...\]).
- `capture_peer_cert_chain`: bool (default: false) - Capture the peer's certificate chain for inspection via getInfo().
- `extra`: array (default: \[\]) - Array of extra options to pass directly to the underlying HTTP client.

```
$response = Http::get(
    'https://api.example.com/data',
    options: [
        'timeout' => 5,
        'verify_peer' => false
    ]
);
```

🚨 Error Handling
----------------

[](#-error-handling)

Any HTTP client or server error will throw a typed exception implementing `ExceptionInterface`.

```
use Osirisgate\Core\Exception\ExceptionInterface;
use Osirisgate\Component\HttpClient\Request\Http;

try {
    $response = Http::get('https://api.example.com/invalid');
} catch (ExceptionInterface $e) {
    echo $e->getMessage(); // Not Found
    echo $e->getCode();    // 404
    print_r($e->format());
}
```

📄 Response Interface
--------------------

[](#-response-interface)

Each request returns a structured object implementing `ResponseInterface`.

```
Get specific field from response
  * ex: $value = $response->get('user.firstname') // return user firstname value or null if not found
  * ex: $value = $response->get('user.account.balance') // return user account balance value or null if not found
```

MethodDescription`getData()`Returns data if 'data' key is present. Otherwise, returns empty array.`get(string $fieldName, mixed $default = null)`Returns the value of a specific field, otherwise returns `$default`.`getStatusCode()`Returns the HTTP status code`getHeaders()`Returns an array of headers`getContent()`Returns raw response body (string)`toArray()`Returns JSON-decoded response`cancel()`Closes the response stream and all related buffers.`getInfo(?string $type = null)`Returns meta information (e.g. url)🧪 Run Tests
-----------

[](#-run-tests)

A full suite of unit tests is included and runs against a public API (`jsonplaceholder.typicode.com`).

```
vendor/bin/phpunit tests
```

🧰 Developer Tools
-----------------

[](#-developer-tools)

### ✅ Code style

[](#-code-style)

```
composer run phpcs-fix
```

### 🧠 Static analysis

[](#-static-analysis)

```
composer run phpstan
```

Or run both checks at once:

```
make check-code-quality
```

📜 License
---------

[](#-license)

This package is licensed under the [MIT License](LICENSE).

👤 Author
--------

[](#-author)

**Ulrich Geraud AHOGLA** Software Engineer — Osirisgate

If you have any questions or suggestions, please contact me via

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance51

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

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 ~0 days

Total

2

Last Release

348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/572d40b1645d8f32e42a4f07bfdab165b975c830d9b8608204cb20a90bd04697?d=identicon)[developer\_osirisgate](/maintainers/developer_osirisgate)

---

Top Contributors

[![osirisgate](https://avatars.githubusercontent.com/u/211675927?v=4)](https://github.com/osirisgate "osirisgate (1 commits)")

---

Tags

http

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[psr/http-client

Common interface for HTTP clients

1.7k680.7M2.1k](/packages/psr-http-client)[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.0k314.0M3.4k](/packages/symfony-http-client)[psr/link

Common interfaces for HTTP links

2.5k144.1M68](/packages/psr-link)

PHPackages © 2026

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