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

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

solophp/http-client
===================

PSR-18 HTTP client

v3.1.0(6mo ago)0122MITPHPPHP ^8.1

Since Jul 13Pushed 6mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (11)Used By (0)

Solo HTTP Client
================

[](#solo-http-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4c47be2eae2dce5e2eace6b89de9930919b56db85ff9170b8e3aac1e0b49f360/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6c6f7068702f687474702d636c69656e742e737667)](https://packagist.org/packages/solophp/http-client)[![License](https://camo.githubusercontent.com/93b4f31e602a0457357cf4b178c54c7e19c80bffd52fce2085fd39c8d482609d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736f6c6f7068702f687474702d636c69656e742e737667)](https://github.com/solophp/http-client/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/148e64e4e2682cd75fc359427e9007a023cb98da89ed02df938eff31ab6f35fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6c6f7068702f687474702d636c69656e742e737667)](https://packagist.org/packages/solophp/http-client)

A simple and elegant PSR-18 HTTP client built on top of Guzzle with fluent API.

Features
--------

[](#features)

- **PSR-18 Compliant**: Implements PSR-18 HTTP Client Interface
- **Fluent API**: Chain methods for easy configuration
- **Built-in Retry Logic**: Automatic retry with exponential backoff
- **Logging Support**: Built-in request/response logging
- **JSON Support**: Easy JSON request/response handling
- **Multipart/Form-Data**: File uploads and form submissions
- **Async Support**: Asynchronous request methods
- **Middleware Support**: Extensible with custom middleware

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

[](#installation)

```
composer require solophp/http-client
```

Quick Start
-----------

[](#quick-start)

```
use Solo\HttpClient\HttpClient;

// Create client
$client = HttpClient::create('https://api.example.com')
    ->timeout(30)
    ->withHeaders(['Content-Type' => 'application/json'])
    ->withToken('your-api-token')
    ->retry(3, 1000);

// Make requests
$response = $client->get('/users');
$users = $response->json();

$response = $client->post('/users', [
    'json' => [
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ]
]);
```

Basic Usage
-----------

[](#basic-usage)

### Creating a Client

[](#creating-a-client)

```
// Simple client
$client = new HttpClient('https://api.example.com');

// With configuration
$client = new HttpClient('https://api.example.com', [
    'timeout' => 30,
    'headers' => ['User-Agent' => 'MyApp/1.0']
]);

// Using fluent API
$client = HttpClient::create('https://api.example.com')
    ->timeout(60)
    ->withHeaders(['X-Custom' => 'value']);
```

### Making Requests

[](#making-requests)

```
// GET request
$response = $client->get('/users');

// POST with JSON data
$response = $client->post('/users', [
    'json' => [
        'name' => 'John',
        'email' => 'john@example.com'
    ]
]);

// PUT request
$response = $client->put('/users/1', [
    'json' => [
        'name' => 'John Updated'
    ]
]);

// PATCH request
$response = $client->patch('/users/1', [
    'json' => [
        'email' => 'john.updated@example.com'
    ]
]);

// DELETE request
$response = $client->delete('/users/1');

// With custom headers and JSON data
$response = $client->post('/users', [
    'json' => ['name' => 'John'],
    'headers' => ['X-Custom' => 'header']
]);
```

### Multipart/Form-Data Requests

[](#multipartform-data-requests)

```
// Simple form fields
$response = $client->postMultipart('/upload', [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => '30'
]);

// Upload file
$response = $client->postMultipart('/upload', [
    'name' => 'John Doe',
    'avatar' => [
        'path' => '/path/to/avatar.jpg'
    ]
]);

// Upload file with custom filename and MIME type
$response = $client->postMultipart('/upload', [
    'name' => 'John Doe',
    'document' => [
        'path' => '/path/to/document.pdf',
        'filename' => 'my-document.pdf',
        'mime_type' => 'application/pdf'
    ]
]);

// Multiple files and fields
$response = $client->postMultipart('/upload', [
    'title' => 'My Photos',
    'description' => 'Vacation photos',
    'photo1' => [
        'path' => '/path/to/photo1.jpg',
        'filename' => 'beach.jpg'
    ],
    'photo2' => [
        'path' => '/path/to/photo2.jpg',
        'filename' => 'sunset.jpg'
    ]
]);

// PUT and PATCH also available
$response = $client->putMultipart('/users/1', [
    'name' => 'Updated Name',
    'avatar' => ['path' => '/path/to/new-avatar.jpg']
]);

$response = $client->patchMultipart('/users/1', [
    'avatar' => ['path' => '/path/to/avatar.jpg']
]);

// Advanced: Using native Guzzle options
$response = $client->post('/upload', [
    'multipart' => [
        [
            'name' => 'field_name',
            'contents' => 'field_value'
        ],
        [
            'name' => 'file',
            'contents' => fopen('/path/to/file.jpg', 'r'),
            'filename' => 'photo.jpg',
            'headers' => ['Content-Type' => 'image/jpeg']
        ]
    ]
]);
```

### Working with Responses

[](#working-with-responses)

```
$response = $client->get('/users/1');

// Check status
if ($response->successful()) {
    $user = $response->json();
    echo $user['name'];
}

// Get specific JSON value
$name = $response->json('name');
$email = $response->json('profile.email');

// Get headers
$contentType = $response->header('Content-Type');
$allHeaders = $response->headers();

// Get raw body
$body = $response->body();
```

### Authentication

[](#authentication)

```
// Bearer token
$client->withToken('your-api-token');

// Custom token type
$client->withToken('your-token', 'Custom');

// Basic auth
$client->withBasicAuth('username', 'password');
```

### Retry Logic

[](#retry-logic)

```
$client->retry(3, 1000); // 3 retries, 1 second delay

// The client will automatically retry on:
// - Network exceptions
// - 429 (Too Many Requests)
// - 5xx server errors
```

### Logging

[](#logging)

```
// Default logging (to error_log)
$client->withLogging();

// Custom callable logger
$client->withLogging(function($message) {
    file_put_contents('http.log', $message . PHP_EOL, FILE_APPEND);
});

// PSR-3 Logger integration
use Psr\Log\LoggerInterface;

$logger = new YourPSR3Logger(); // Any PSR-3 compatible logger
$client->withLogging($logger); // Automatically uses info level
```

### Async Requests

[](#async-requests)

```
// Async GET
$promise = $client->getAsync('/users');
$response = $promise->wait();

// Async POST
$promise = $client->postAsync('/users', ['json' => ['name' => 'John']]);
$response = $promise->wait();
```

### Custom Requests

[](#custom-requests)

```
// Custom method with options
$response = $client->request('POST', '/custom', [
    'json' => ['data' => 'value'],
    'headers' => ['X-Custom' => 'header'],
    'timeout' => 10
]);

// Async custom request
$promise = $client->requestAsync('PUT', '/custom', [
    'json' => ['data' => 'value']
]);
```

Error Handling
--------------

[](#error-handling)

```
try {
    $response = $client->get('/users');

    if ($response->clientError()) {
        // Handle 4xx errors
        echo "Client error: " . $response->status();
    } elseif ($response->serverError()) {
        // Handle 5xx errors
        echo "Server error: " . $response->status();
    }
} catch (\RuntimeException $e) {
    // Handle network/connection errors
    echo "Request failed: " . $e->getMessage();
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Accessing Guzzle Client

[](#accessing-guzzle-client)

```
$guzzleClient = $client->getClient();
// Use Guzzle client directly for advanced features
```

### Custom Configuration

[](#custom-configuration)

```
$client = new HttpClient('https://api.example.com', [
    'timeout' => 30,
    'connect_timeout' => 10,
    'http_errors' => false,
    'verify' => false, // Disable SSL verification (not recommended for production)
    'proxy' => 'http://proxy.example.com:8080'
]);
```

Development
-----------

[](#development)

```
# Run code style check
composer cs

# Fix code style
composer cs-fix

# Run static analysis
composer phpstan
```

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

[](#requirements)

- PHP 8.1 or higher
- Guzzle HTTP 7.9 or higher
- PSR-3 Logger (optional, for logging functionality)

License
-------

[](#license)

MIT License - see LICENSE file for details.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance66

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Recently: every ~79 days

Total

10

Last Release

206d ago

Major Versions

v1.0.3 → v2.0.02024-12-04

v2.1.1 → v3.0.02025-09-30

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f29817cec408d033cd4441c8f760e3ae40248dc0f66856a09080d282aee6959?d=identicon)[Vitaliy Olos](/maintainers/Vitaliy%20Olos)

---

Top Contributors

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

---

Tags

phphttp clientpsr-18

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[claude-php/claude-php-sdk

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

13920.7k2](/packages/claude-php-claude-php-sdk)[simpod/clickhouse-client

PHP ClickHouse Client

19116.7k](/packages/simpod-clickhouse-client)

PHPackages © 2026

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