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

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

mj4444/simple-http-client
=========================

Simple Http Client

v0.2.0(2mo ago)29283UnlicensePHPPHP ^8.2

Since Oct 14Pushed 2mo agoCompare

[ Source](https://github.com/mj4444ru/simple-http-client)[ Packagist](https://packagist.org/packages/mj4444/simple-http-client)[ RSS](/packages/mj4444-simple-http-client/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (4)Used By (3)

Simple Http Client
==================

[](#simple-http-client)

This client makes complex HTTP requests easy.

It's useful for building API clients, various parsers, and handling complex multi-step request workflows.

Key Features
------------

[](#key-features)

- The client, request, and response are fully abstract and interface-based.
- A set of ready-to-use classes simplifies working with any types of sent and received data.
- Tools for working with streaming data (upload, download).
- A dedicated client for JSON responses.
- Using your own implementations of request and response interfaces keeps your code organized.

Warning

Versions of this package earlier than "v1" may be incompatible. When connecting, please specify the exact package version to avoid automatic updates.

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

[](#installation)

### Via composer

[](#via-composer)

```
composer require --prefer-dist mj4444/simple-http-client
```

### By cloning the code

[](#by-cloning-the-code)

```
git clone https://github.com/mj4444ru/simple-http-client.git
```

Add the following lines to the `composer.json` file:

```
"autoload": {
    "psr-4": {
        "Mj4444\\SimpleHttpClient\\": "simple-http-client/src/"
    }
}

```

Examples
--------

[](#examples)

### Simple requests

[](#simple-requests)

#### Get request

[](#get-request)

```
use Mj4444\SimpleHttpClient\CurlHttpClient;
use Mj4444\SimpleHttpClient\HttpRequest\HttpRequest;

$client = new CurlHttpClient();
$request = new HttpRequest('http://www.google.com');
$response = $client->request($request);

$responseHttpCode = $response->getHttpCode();
$responseUrl = $response->getUrl();
$responseEffectiveUrl = $response->getEffectiveUrl();
$responseContentType = $response->getContentType();
$responseBody = $response->getBody();

echo $responseHttpCode . PHP_EOL;
echo $responseUrl . PHP_EOL;
echo $responseEffectiveUrl . PHP_EOL;
echo $responseContentType . PHP_EOL;
echo PHP_EOL . $responseBody . PHP_EOL . PHP_EOL;
```

#### Get request with query

[](#get-request-with-query)

```
use Mj4444\SimpleHttpClient\HttpRequest\HttpRequest;

$request = new HttpRequest('http://www.google.com/search?q=demo');
```

```
use Mj4444\SimpleHttpClient\HttpRequest\HttpRequest;

$request = new HttpRequest('http://www.google.com/search', ['q' => 'demo']);
```

#### Post request

[](#post-request)

```
use Mj4444\SimpleHttpClient\HttpRequest\Body\MultipartBody\File;
use Mj4444\SimpleHttpClient\HttpRequest\Body\MultipartBody\StringFile;
use Mj4444\SimpleHttpClient\HttpRequest\HttpMethod;
use Mj4444\SimpleHttpClient\HttpRequest\HttpRequest;

$request = new HttpRequest('http://www.google.com', null, HttpMethod::Post);

$request->setUrlencodedBody(['q' => 'demo']);

$request->setMultipartFormBody([
    'field1' => 'value1',
    'field2' => 2,
    'field3' => new File($fileName, $postName, $mime),
    'field4' => new StringFile($data, $postName, $mime),
]);

$request->setJsonBody('demo');

$request->setStringBody(http_build_query(['q' => 'demo']), 'application/x-www-form-urlencoded');

$request->setNoBody();

$request->setFileBody(...);

$request->setStreamBody(...);

$request->setStringStreamBody(...);
```

#### JSON client

[](#json-client)

```
use Mj4444\SimpleHttpClient\CurlHttpClient;
use Mj4444\SimpleHttpClient\HttpRequest\Body\NoBody;
use Mj4444\SimpleHttpClient\HttpRequest\Body\UrlencodedBody;
use Mj4444\SimpleHttpClient\JsonHttpClient;

$client = new JsonHttpClient(new CurlHttpClient());

$data = $client->get('https://example.com', ['q' => 'demo']);

$data = $client->post('https://example.com', ['body' => 'demo'], ['q' => 'demo']);

$data = $client->post('https://example.com', new NoBody());

$data = $client->post('https://example.com', new UrlencodedBody([['q' => 'demo']]));
```

#### Extended request

[](#extended-request)

```
use Mj4444\SimpleHttpClient\CurlHttpClient;
use Mj4444\SimpleHttpClient\HttpRequest\HttpRequestEx;

$client = new CurlHttpClient();
$fp = fopen('php://temp', 'rb+');
$request = new HttpRequestEx('https://google.com');
$request->setFollowLocation(true);
$request->setResourceForResponseBody($fp);
$progressCallback = static function ($bytesToDownload, $bytesDownloaded, $bytesToUpload, $bytesUploaded): bool {
    echo sprintf("%d / %d -- %d / %d\n", $bytesToDownload, $bytesDownloaded, $bytesToUpload, $bytesUploaded);

    return true;
};
$request->setProgressCallback($progressCallback);
$response = $client->request($request);
$response->checkHttpCode(200);
```

Supported Body
--------------

[](#supported-body)

- [FileBody](src/HttpRequest/Body/FileBody.php)
- [JsonBody](src/HttpRequest/Body/JsonBody.php)
- [MultipartFormBody](src/HttpRequest/Body/MultipartFormBody.php)
    - [File](src/HttpRequest/Body/MultipartBody/File.php)
    - [StringFile](src/HttpRequest/Body/MultipartBody/StringFile.php)
- [NoBody](src/HttpRequest/Body/NoBody.php)
- [StreamBody](src/HttpRequest/Body/StreamBody.php)
- [StringBody](src/HttpRequest/Body/StringBody.php)
- [StringStreamBody](src/HttpRequest/Body/StringStreamBody.php)
- [UrlencodedBody](src/HttpRequest/Body/UrlencodedBody.php)
- Your Body Implementations

Run tests
---------

[](#run-tests)

```
vendor/bin/codecept run
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance85

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity40

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

Total

3

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/95adc63b893241604860f7db48dafdbdd3db24e4040a04330e77ffbcc77e60c0?d=identicon)[mj4444](/maintainers/mj4444)

---

Top Contributors

[![mj4444ru](https://avatars.githubusercontent.com/u/9354685?v=4)](https://github.com/mj4444ru "mj4444ru (12 commits)")

---

Tags

httpphpclientSimple

###  Code Quality

TestsCodeception

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[smi2/phpclickhouse

PHP ClickHouse Client

84711.6M80](/packages/smi2-phpclickhouse)

PHPackages © 2026

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