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

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

pdeans/http
===========

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

v2.0.4(1y ago)1466.2k↓50%23MITPHPPHP ^8.1

Since Jul 17Pushed 1y ago1 watchersCompare

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

READMEChangelog (8)Dependencies (1)Versions (13)Used By (3)

HTTP Client Library
-------------------

[](#http-client-library)

Lightweight [PSR-7 HTTP message interfaces](https://www.php-fig.org/psr/psr-7/) cURL client with support for [PSR-17 HTTP factories interfaces](https://www.php-fig.org/psr/psr-17/).

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

[](#installation)

Install via [Composer](https://getcomposer.org/).

```
composer require pdeans/http
```

Usage
-----

[](#usage)

The cURL client is built on top of the [Laminas Diactoros](https://docs.laminas.dev/laminas-diactoros/) PSR-7 and PSR-17 implementations.

### Configuring the Client

[](#configuring-the-client)

The client accepts an optional associative array of [curl options](http://php.net/curl_setopt) as the first parameter to configure the cURL client. Please note that the following cURL options cannot be set in order to comply with PSR-7 standards. Instead, these options should be provided as part of the request options:

- CURLOPT\_CUSTOMREQUEST
- CURLOPT\_FOLLOWLOCATION
- CURLOPT\_HEADER
- CURLOPT\_HTTP\_VERSION
- CURLOPT\_HTTPHEADER
- CURLOPT\_NOBODY
- CURLOPT\_POSTFIELDS
- CURLOPT\_RETURNTRANSFER
- CURLOPT\_URL
- CURLOPT\_USERPWD

The following is an example of how to create and configure the client:

```
use pdeans\Http\Client;

$client = new Client();

// With options
$client = new Client([
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_SSL_VERIFYHOST => true,
]);
```

### HTTP Requests

[](#http-requests)

The client comes bundled with helper methods to provide a convenient way for issuing the supported HTTP request methods.

`GET`, `HEAD`, and `TRACE` methods take the following parameters:

- String representation of the target url **OR** a class instance that implements the PSR-7 `Psr\Http\Message\UriInterface`.
- Associative array of headers `[headerName => headerValue]`.

`POST`, `PUT`, `PATCH`, `OPTIONS`, and `DELETE` methods take the two parameters listed above, plus an optional 3rd parameter for the request body:

- String of request body data **OR** a class instance that implements the PSR-7 `Psr\Http\Message\StreamInterface` **OR** a `resource`.

#### Request Usage

[](#request-usage)

```
// GET request with header
$response = $client->get('https://example.com/1', ['custom-header' => 'header/value']);

// GET request without header
$response = $client->get('https://example.com/2');

// HEAD request
$response = $client->head('https://example.com/2');

// TRACE request
$response = $client->trace('https://example.com/2');

$headers = [
    'Content-Type'  => 'application/json',
    'Accept'        => 'application/json',
    'Authorization' => 'Basic ' . base64_encode('username:password'),
];

$data = json_encode(['json' => 'json data']);

// POST request with headers and request body
$response = $client->post('https://example.com/4', $headers, $data);

// PUT request
$response = $client->put('https://example.com/4', $headers, $data);

// PATCH request
$response = $client->patch('https://example.com/4', $headers, $data);

// OPTIONS request
$response = $client->options('https://example.com/4', $headers, $data);

// DELETE request
$response = $client->delete('https://example.com/4', $headers, $data);
```

If more control over the request is needed, the helper methods can be bypassed and the `sendRequest` method may be called directly. This method accepts a class instance that implements the PSR-7 `Psr\Http\Message\RequestInterface`.

Example `GET` request using the `RequestFactory` class instance:

```
use pdeans\Http\Factories\RequestFactory;

$request = (new RequestFactory())->createRequest('GET', 'https://example.com/1');

$response = $client->sendRequest($request);
```

Example `POST` request using the `Request` class instance:

```
use pdeans\Http\Request;

$request = new Request(
    uri: 'https://example.com',
    method: 'POST',
    headers: ['Content-Type' => 'application/json'],
    body: $client->getStream(json_encode(['json' => 'json data']))
);

$response = $client->sendRequest($request);
```

### HTTP Responses

[](#http-responses)

Each HTTP request returns a `pdeans\Http\Response` class instance, which is an implementation of the PSR-7 `Psr\Http\Message\ResponseInterface`.

#### Response Usage

[](#response-usage)

```
// Issue request
$response = $client->get('https://example.com/1', ['custom-header' => 'header/value']);

// Response body output
echo (string) $response->getBody();

// Response headers output
var_dump($response->getHeaders());
var_dump($response->getHeader('custom-header'));
var_dump($response->hasHeader('custom-header'));
echo $response->getHeaderLine('custom-header');

// Response status code output
echo $response->getStatusCode();

// Response reason phrase output
echo $response->getReasonPhrase();
```

### PSR-17 Factories

[](#psr-17-factories)

The following HTTP factory classes are available and each implement their associated PSR-17 factory interface:

- `pdeans\Http\Factories\RequestFactory` implements `Psr\Http\Message\RequestFactoryInterface`
- `pdeans\Http\Factories\ResponseFactory` implements `Psr\Http\Message\ResponseFactoryInterface`
- `pdeans\Http\Factories\ServerRequestFactory` implements `Psr\Http\Message\ServerRequestFactoryInterface`
- `pdeans\Http\Factories\StreamFactory` implements `Psr\Http\Message\StreamFactoryInterface`
- `pdeans\Http\Factories\UploadedFileFactory` implements `Psr\Http\Message\UploadedFileFactoryInterface`
- `pdeans\Http\Factories\UriFactory` implements `Psr\Http\Message\UriFactoryInterface`

#### Factory Usage

[](#factory-usage)

```
use pdeans\Http\Factories\RequestFactory;
use pdeans\Http\Factories\ResponseFactory;
use pdeans\Http\Factories\ServerRequestFactory;
use pdeans\Http\Factories\StreamFactory;
use pdeans\Http\Factories\UploadedFileFactory;
use pdeans\Http\Factories\UriFactory;

// Psr\Http\Message\RequestFactoryInterface
$requestFactory = new RequestFactory();

// Psr\Http\Message\RequestInterface
$request = $requestFactory->createRequest('GET', 'https://example.com/1');

// Psr\Http\Message\ResponseFactoryInterface
$responseFactory = new ResponseFactory();

// Psr\Http\Message\ResponseInterface
$response = $responseFactory->createResponse();

// Psr\Http\Message\ServerRequestFactoryInterface
$serverRequestFactory = new ServerRequestFactory();

// Psr\Http\Message\ServerRequestInterface
$serverRequest = $serverRequestFactory->createServerRequest('GET', 'https://example.com/2');

// Psr\Http\Message\StreamFactoryInterface
$streamFactory = new StreamFactory();

// Psr\Http\Message\StreamInterface
$stream = $streamFactory->createStream();
$fileStream = $streamFactory->createStreamFromFile('dir/api.json');
$resourceStream = $streamFactory->createStreamFromResource(fopen('php://temp', 'r+'));

// Psr\Http\Message\UploadedFileFactoryInterface
$uploadedFileFactory = new UploadedFileFactory();

// Psr\Http\Message\UploadedFileInterface
$uploadedFile = $uploadedFileFactory->createUploadedFile($fileStream);

// Psr\Http\Message\UriFactoryInterface
$uriFactory = new UriFactory();

// Psr\Http\Message\UriInterface
$uri = $uriFactory->createUri();
```

Further Reading
---------------

[](#further-reading)

As this library is a layer built upon existing libraries and standards, it is encouraged that you read through the documentation of these libraries and standards to get a better understanding of how the various components work.

- [PSR-7: HTTP Message Interfaces](https://www.php-fig.org/psr/psr-7/)
- [PSR-17: HTTP Factories Interfaces](https://www.php-fig.org/psr/psr-17/)
- [Laminas Diactoros Library](https://docs.laminas.dev/laminas-diactoros/)
- [PHP Client URL Library](https://www.php.net/manual/en/book.curl.php)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance40

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% 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 ~243 days

Recently: every ~131 days

Total

12

Last Release

552d ago

Major Versions

v1.2.1 → v2.0.02023-06-04

PHP version history (5 changes)v1.0.0PHP &gt;=5.6

v1.1.0PHP ^5.4 || ^7.0

v1.1.3PHP ^7.1

v1.2.1PHP ^7.1 || ^8.0

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9fb3ce86d5dadb84c3c9248c8529641cc0a7075a1057cd4e1c45ba32acedaaa5?d=identicon)[pdeans](/maintainers/pdeans)

![](https://www.gravatar.com/avatar/567f90134e637eacb09970991177499a4b70bc73768c84c7b0c3f2187e6ada2e?d=identicon)[mivaprofsrvcs](/maintainers/mivaprofsrvcs)

---

Top Contributors

[![pdeans](https://avatars.githubusercontent.com/u/7277991?v=4)](https://github.com/pdeans "pdeans (39 commits)")[![tssge](https://avatars.githubusercontent.com/u/2301748?v=4)](https://github.com/tssge "tssge (1 commits)")

---

Tags

httpresponserequestpsr-7streamurlmessageuriclientpsr-17curlpsr7psr17

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

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

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

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

PSR-7 message implementation that also provides common utility methods

1079.8k10](/packages/workerman-psr7)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

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