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

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

solidworx/simple-http
=====================

Provides a fluent interface for HTTP requests

0.1.1(2y ago)0758MITPHPPHP &gt;=7.4

Since Feb 20Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/SolidWorx/SimpleHttp)[ Packagist](https://packagist.org/packages/solidworx/simple-http)[ Docs](https://github.com/SolidWorx/SimpleHttp)[ RSS](/packages/solidworx-simple-http/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (23)Versions (3)Used By (0)

SimpleHttp
==========

[](#simplehttp)

A PHP library that provides a fluent interface for making HTTP requests.

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

[](#installation)

You can install the package via composer:

```
composer require solidworx/simple-http
```

This package is an implementation of [PSR-18 (HTTP Client)](https://www.php-fig.org/psr/psr-18/) and requires a PSR-18 compatible HTTP client. If you don't have one installed already, you can use Guzzle:

```
composer require guzzlehttp/guzzle php-http/guzzle7-adapter
```

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

[](#basic-usage)

### Creating a Client

[](#creating-a-client)

```
use SolidWorx\SimpleHttp\HttpClient;

// Create a new client
$client = HttpClient::create();

// Create a client with a base URL
$client = HttpClient::createForBaseUrl('https://api.example.com');
```

### Making a Simple GET Request

[](#making-a-simple-get-request)

```
use SolidWorx\SimpleHttp\HttpClient;

$response = HttpClient::create()
    ->url('https://api.example.com/users')
    ->get()
    ->request();

// Get the response content as a string
$content = $response->getContent();

// Get the response status code
$statusCode = $response->getStatusCode();

// Get the response headers
$headers = $response->getHeaders();
```

### Making a POST Request with JSON Data

[](#making-a-post-request-with-json-data)

```
use SolidWorx\SimpleHttp\HttpClient;

$response = HttpClient::create()
    ->url('https://api.example.com/users')
    ->post()
    ->json([
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ])
    ->request();

// Parse the JSON response into an array
$data = $response->toArray();
```

HTTP Methods
------------

[](#http-methods)

SimpleHttp supports all standard HTTP methods:

```
// GET request
$client->get()->request();

// POST request
$client->post()->request();

// PUT request
$client->put()->request();

// PATCH request
$client->patch()->request();

// DELETE request
$client->delete()->request();

// OPTIONS request
$client->options()->request();

// Custom method
$client->method('CUSTOM')->request();
```

Request Configuration
---------------------

[](#request-configuration)

### Headers

[](#headers)

```
$client = HttpClient::create()
    ->url('https://api.example.com')
    ->header('Accept', 'application/json')
    ->header('X-API-Key', 'your-api-key');
```

### Query Parameters

[](#query-parameters)

```
$client = HttpClient::create()
    ->url('https://api.example.com/search')
    ->query([
        'q' => 'search term',
        'page' => 1,
        'limit' => 10
    ]);
```

### Request Body

[](#request-body)

#### Form Data

[](#form-data)

```
$client = HttpClient::create()
    ->url('https://api.example.com/form')
    ->post()
    ->formData([
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ]);
```

#### JSON

[](#json)

```
$client = HttpClient::create()
    ->url('https://api.example.com/users')
    ->post()
    ->json([
        'name' => 'John Doe',
        'email' => 'john@example.com'
    ]);
```

#### Raw Body

[](#raw-body)

```
$client = HttpClient::create()
    ->url('https://api.example.com/data')
    ->post()
    ->body('Raw request body content');
```

### File Uploads

[](#file-uploads)

```
$client = HttpClient::create()
    ->url('https://api.example.com/upload')
    ->post()
    ->uploadFile('file', '/path/to/file.pdf');
```

Authentication
--------------

[](#authentication)

### Basic Authentication

[](#basic-authentication)

```
$client = HttpClient::create()
    ->url('https://api.example.com/protected')
    ->basicAuth('username', 'password');
```

### Bearer Token Authentication

[](#bearer-token-authentication)

```
$client = HttpClient::create()
    ->url('https://api.example.com/protected')
    ->bearerToken('your-token');
```

SSL Configuration
-----------------

[](#ssl-configuration)

### Disable SSL Verification

[](#disable-ssl-verification)

```
$client = HttpClient::create()
    ->url('https://api.example.com')
    ->disableSslVerification();
```

HTTP Version
------------

[](#http-version)

```
// Use HTTP/1.1 (default)
$client = HttpClient::create()
    ->url('https://api.example.com')
    ->httpVersion(HttpClient::HTTP_VERSION_1);

// Use HTTP/2
$client = HttpClient::create()
    ->url('https://api.example.com')
    ->http2();
```

Response Handling
-----------------

[](#response-handling)

### Getting Response Data

[](#getting-response-data)

```
$response = HttpClient::create()
    ->url('https://api.example.com/users')
    ->get()
    ->request();

// Get status code
$statusCode = $response->getStatusCode();

// Get headers
$headers = $response->getHeaders();
$contentType = $response->getHeaderLine('Content-Type');

// Get body as string
$content = $response->getContent();

// Parse JSON response
$data = $response->toArray();
```

### Saving Response to a File

[](#saving-response-to-a-file)

```
// Save to a file
$response = HttpClient::create()
    ->url('https://example.com/large-file.zip')
    ->get()
    ->saveToFile('/path/to/save/file.zip')
    ->request();

// Append to a file
$response = HttpClient::create()
    ->url('https://example.com/data.txt')
    ->get()
    ->appendToFile('/path/to/existing/file.txt')
    ->request();

// Save response to a file after receiving it
$response = HttpClient::create()
    ->url('https://example.com/image.jpg')
    ->get()
    ->request();

$response->saveToFile('/path/to/save/image.jpg');
```

### Progress Tracking

[](#progress-tracking)

```
$response = HttpClient::create()
    ->url('https://example.com/large-file.zip')
    ->progress(function ($progress) {
        // $progress->getDownloaded() - bytes downloaded
        // $progress->getTotal() - total bytes (if known)
        echo "Downloaded {$progress->getDownloaded()} of {$progress->getTotal()} bytes\n";
    })
    ->request();
```

Caching Responses
-----------------

[](#caching-responses)

```
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$cache = new FilesystemAdapter();

$response = HttpClient::create()
    ->url('https://api.example.com/data')
    ->cacheResponse($cache, 3600) // Cache for 1 hour
    ->request();
```

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

[](#error-handling)

```
use SolidWorx\SimpleHttp\HttpClient;
use Http\Client\Exception\HttpException;

try {
    $response = HttpClient::create()
        ->url('https://api.example.com/users')
        ->get()
        ->request();
} catch (HttpException $e) {
    // Get the error response
    $errorResponse = $e->getResponse();

    // Get the status code
    $statusCode = $errorResponse->getStatusCode();

    // Get the error message
    $errorMessage = $e->getMessage();

    // Get the response body
    $errorBody = $errorResponse->getBody()->getContents();
}
```

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

[](#advanced-usage)

### Using with a Base URL

[](#using-with-a-base-url)

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

// Now you can make requests to endpoints relative to the base URL
$response = $client->path('/users')->get()->request();
$response = $client->path('/posts')->get()->request();
```

### Immutability

[](#immutability)

All methods in the SimpleHttp client return a new instance, making the client immutable:

```
$client = HttpClient::create()->url('https://api.example.com');

// These create new instances, they don't modify the original $client
$jsonClient = $client->header('Accept', 'application/json');
$authClient = $client->bearerToken('your-token');

// Original client remains unchanged
$response = $client->request();
```

This allows you to create reusable client configurations:

```
$baseClient = HttpClient::createForBaseUrl('https://api.example.com')
    ->bearerToken('your-token')
    ->header('Accept', 'application/json');

// Reuse the base client for different endpoints
$usersResponse = $baseClient->path('/users')->get()->request();
$postsResponse = $baseClient->path('/posts')->get()->request();
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance40

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Total

2

Last Release

787d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b374a94bdeca7fd62b1debf578810b58c63b6bb73bb648c4d3b3876aefe05a1d?d=identicon)[pierredup](/maintainers/pierredup)

---

Top Contributors

[![pierredup](https://avatars.githubusercontent.com/u/144858?v=4)](https://github.com/pierredup "pierredup (48 commits)")

---

Tags

httphttp client

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[friendsofsymfony/http-cache

Tools to manage HTTP caching proxies with PHP

36114.7M36](/packages/friendsofsymfony-http-cache)[laudis/neo4j-php-client

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

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

Symfony integration for HTTPlug

38921.0M54](/packages/php-http-httplug-bundle)[simpod/clickhouse-client

PHP ClickHouse Client

19116.7k](/packages/simpod-clickhouse-client)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

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

PHPackages © 2026

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