PHPackages                             drewlabs/psr18 - 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. drewlabs/psr18

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

drewlabs/psr18
==============

PSR18 compatible http client based on PHP curl client library

v0.4.3(1y ago)21592MITPHP

Since Mar 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/azandrew-sidoine/curl-psr18)[ Packagist](https://packagist.org/packages/drewlabs/psr18)[ RSS](/packages/drewlabs-psr18/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (12)Used By (2)

cURL PSR18 compatible client
============================

[](#curl-psr18-compatible-client)

This project provides a PSR18 client implementation based on the cURL client object.

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

[](#installation)

Recommended way to install the library is by using PHP package manager `composer` running the command below:

> composer require drewlabs/psr18

Usage
-----

[](#usage)

### PSR18 Client

[](#psr18-client)

The package comes with a PSR18 compatible Client using the PHP cURL library. To creates an instance of the client:

```
use Drewlabs\Psr18\Client;

// Creates an instance of the cURL client
$client = Client::new(/* Parameters */);

// Passing constructor parameters
$client = Client::new('http:://127.0.0.1:5000');

// Passing customize client options
$client = Client::new([
    /* Custom client options */
]);
```

### Client options

[](#client-options)

Client options, provide developpers with a way to override parameters passed to the `Client::sendRequest()` method. The package provide a PHP class for building client option as alternative to using PHP dictionary type (a.k.a PHP array).

- Creating the client options using a factory function

```
use Drewlabs\Curl\ClientOptions;

//
$clientOptions = ClientOptions::create([
    'verify' => false,
    'sink' => null,
    'force_resolve_ip' => false,
    'proxy' => ['http://proxy.app-ip.com'],
    'cert' => null,
    'ssl_key' => ['/home/webhost/.ssh/pub.key'],
    'progress' => new class {
        // Declare the function to handle the progress event
        public function __invoke()
        {
            // Handle the progress event
        }
    },
    'base_url' => 'http://127.0.0.1:3000',
    'connect_timeout' => 1000,
    'request' => [
        'headers' => [
            'Content-Type' => 'application/json'
        ],
        'timeout' => 10,
        'auth' => ['MyUser', 'MyPassword', 'digest'],
        'query' => [
            'post_id' => 2, 'comments_count' => 1
        ],
        'encoding' => 'gzip,deflate'
    ],
    'cookies' => [
        'clientid' => 'myClientID', 'clientsecret' => 'MySuperSecret'
    ],
]);
```

- Using the fluent API

Alternative to using the factory function, we can use the fluent API for creating a client options. The fluent API attemps to reduce developper typo errors by providing methods to defining option values:

```
use Drewlabs\Curl\ClientOptions;
use Drewlabs\Curl\RequestOptions;

$clientOptions = new ClientOptions;

$clientOptions->setBaseURL(/* base url*/)
    ->setRequest(RequestOptions::create([]))
    ->setConnectTimeout(150)
    ->setVerify(false)
    // Psr Stream to write response output to
    ->setSink()
    ->setForceResolveIp(true)
    ->setProxy($proxy_ip, [$proxy_port, $user, $password]) // port, user & password are optional depending on the proxy configuration
    ->setCert('/path/to/ssl/certificate');
    ->setSslKey('/path/to/ssl/key')
    ->setProgress(function($curl, ...$progress) {
        // Handle cURL progress event
    })
    ->setCookies([]); // List of request cookies
```

**Note**API for request options &amp; client option fluent API can be found in the API reference documentation.

### Sending a PSR18 request

[](#sending-a-psr18-request)

Sending request is simply as using any PSR18 compatible library:

```
use Drewlabs\Psr18\Client;
use Drewlabs\Psr7\Request;

// Creates an instance of the cURL client
$client = Client::new([
    // Parameters to client options ...
        'base_url' => 'http://127.0.0.1:3000',
    'connect_timeout' => 1000,
    'request' => [
        'headers' => [
            'Content-Type' => 'application/json'
        ],
        'timeout' => 10,
        'auth' => ['MyUser', 'MyPassword', 'digest'],
        'query' => [
            'post_id' => 2, 'comments_count' => 1
        ],
        'encoding' => 'gzip,deflate'
    ],
]);

$response = $client->sendRequest(new Request()); // \Psr7\Http\ResponseInterface
```

To send a JSON request, developpers call the `Client::json()` method before sending the request to the server:

```
use Drewlabs\Psr18\Client;

// Creates an instance of the cURL client
$client = new Client(/* Parameters */);

// Sends a request with application/json as Content-Type
$client->json()->sendRequest(/* PSR7 compatible Request */);
```

Alternatively, to send a `multipart/form-data` request, developpers call the `Client::multipart()` method before sending the request to the server:

```
use Drewlabs\Psr18\Client;

// Creates an instance of the cURL client
$client = new Client(
        'verify' => false,
        'request' => [
            'headers' => ['Accept' => 'application/json'],
            'body' => [ /*...*/ ],
        ],
);

// Sends a request with application/json as Content-Type
$client->multipart()->sendRequest(new Request());
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

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

Recently: every ~99 days

Total

11

Last Release

613d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (19 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewlabs-psr18/health.svg)

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

###  Alternatives

[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.8k44](/packages/laudis-neo4j-php-client)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

157.1k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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