PHPackages                             elfsundae/httpclient - 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. elfsundae/httpclient

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

elfsundae/httpclient
====================

A smart Guzzle wrapper provides convenient method chaining, global request options, and magic methods to customize request options.

2.2.0(4y ago)05241MITPHPPHP &gt;=5.6.4CI failing

Since Jun 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ElfSundae/httpclient)[ Packagist](https://packagist.org/packages/elfsundae/httpclient)[ Docs](https://github.com/ElfSundae/httpclient)[ RSS](/packages/elfsundae-httpclient/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (8)Used By (1)

HTTP Client
===========

[](#http-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/82ff136679fe99c191c4aa74c92d4557d987bb0191eb63e0b85027e0cb48741e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6673756e6461652f68747470636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfsundae/httpclient)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![tests](https://github.com/ElfSundae/httpclient/actions/workflows/tests.yml/badge.svg)](https://github.com/ElfSundae/httpclient/actions/workflows/tests.yml)[![StyleCI](https://camo.githubusercontent.com/8778b18ec5d2e204ee8d0eb8f5f1b33b2b04aa290470cfd4140a4d90666af38a/68747470733a2f2f7374796c6563692e696f2f7265706f732f39343334313638312f736869656c64)](https://styleci.io/repos/94341681)[![SymfonyInsight Grade](https://camo.githubusercontent.com/a201297582e73393ad9e780d08c31ed9ae7faf3af44c0c30ac4b9cdb1c9f1b44/68747470733a2f2f696d672e736869656c64732e696f2f73796d666f6e792f692f67726164652f34353230363337382d393666662d346530372d623661312d3538326663356264653566353f7374796c653d666c61742d737175617265)](https://insight.symfony.com/projects/45206378-96ff-4e07-b6a1-582fc5bde5f5)[![Quality Score](https://camo.githubusercontent.com/b1208cbb33cb3fa1f0b38c546b7b8c187b46c37f38ba3f1a3be307eef8d529b7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f456c6653756e6461652f68747470636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ElfSundae/httpclient)[![Code Coverage](https://camo.githubusercontent.com/d71dfee3b0f04a242ad44b660bc50b102b53df3993eb641b47da83f8dc7c41ee/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f456c6653756e6461652f68747470636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ElfSundae/httpclient/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/e851e958d13d6f08869def68ead33bd115d8aa28e69b096a289162b369eb194b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c6673756e6461652f68747470636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfsundae/httpclient)

HttpClient is a smart [Guzzle](https://github.com/guzzle/guzzle) wrapper provides convenient method chaining, global request options, and magic methods to customize [request options](http://docs.guzzlephp.org/en/stable/request-options.html).

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

[](#installation)

```
$ composer require elfsundae/httpclient
```

Usage
-----

[](#usage)

```
use ElfSundae\HttpClient;
```

### Fetching Response Content

[](#fetching-response-content)

```
$html = (new HttpClient)->fetchContent('http://httpbin.org');

$data = (new HttpClient)->fetchJson('https://httpbin.org/ip');
```

### Making Requests

[](#making-requests)

```
$client = HttpClient::create('https://httpbin.org')
    ->catchExceptions(true)
    ->httpErrors(false)
    ->auth(['user', 'passwd']);

$query = $client->query(['foo' => 'bar'])->getJson('/get');

$form = $client->formParams(['foo' => 'bar'])->postJson('/post');

$json = $client->json(['foo' => 'bar'])->putJson('/put');

$download = $client->saveTo('image.png')->get('/image/png');

$file = fopen('image.png', 'r');
$uploadBody = $client->body($file)->postJson('/post');

$multipart = [
    'foo' => 'bar',
    'file' => $file,
    'image' => [
        'contents' => fopen('image.png', 'r'),
        'filename' => 'filename.png',
    ],
];
$formData = $client->multipart($multipart)->postJson('/post');
```

### Async Requests

[](#async-requests)

```
$promise = $client->json($data)->getAsync('/get');

$promise = $client->formParams($data)->postAsync('/post');
```

### Applying Request Options

[](#applying-request-options)

Using the `option` method:

```
$client
    ->option('cert', $cert)
    ->option([
        'debug' => true,
        'headers.Content-Type' => 'application/json',
    ]);
```

Or using `camelCase` of any option name as a method on the client:

```
$client
    ->allowRedirects(false)
    ->timeout(20)
    ->cookies($cookieJar)
    ->headers([
        'X-Foo' => 'foo',
    ]);
```

In addition, you may use `header`, `accept`, `acceptJson`, `userAgent` or `contentType` to set request headers:

```
$client
    ->header('X-Foo', 'foo');
    ->header('X-Bar', 'bar');
    ->acceptJson()
    ->contentType('text/plain')
    ->userAgent('HttpClient/2.0')
```

### Global Default Request Options

[](#global-default-request-options)

The static `setDefaultOptions` method can be used to configure default options for every new client instance:

```
HttpClient::setDefaultOptions([
    'catch_exceptions' => true,
    'http_errors' => false,
    'connect_timeout' => 5,
    'timeout' => 20,
    'headers.User-Agent' => 'HttpClient/2.0',
]);
```

### Catching Guzzle Exceptions

[](#catching-guzzle-exceptions)

The `catchExceptions` method determines whether to catch Guzzle exceptions or not.

```
$response = $client->catchExceptions(true)->get('/api/path');

try {
    $response = $client->catchExceptions(false)->get('/api/path');
} catch (Exception $e) {
    // ...
}
```

Testing
-------

[](#testing)

```
$ composer test
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT License](LICENSE.md).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~382 days

Total

7

Last Release

1540d ago

Major Versions

1.1.1 → 2.0.02018-01-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c708b9bd4fcd09378112b235c310162a01d656b85946f1357562b6820c75ee6?d=identicon)[ElfSundae](/maintainers/ElfSundae)

---

Top Contributors

[![ElfSundae](https://avatars.githubusercontent.com/u/526008?v=4)](https://github.com/ElfSundae "ElfSundae (197 commits)")

---

Tags

httpclientGuzzlechaining

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elfsundae-httpclient/health.svg)

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

###  Alternatives

[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

11259.2k](/packages/e-moe-guzzle6-bundle)[amphp/http-client-guzzle-adapter

Guzzle adapter for Amp's HTTP client.

1523.6k1](/packages/amphp-http-client-guzzle-adapter)[opgg/riotquest

RiotQuest, PHP RiotAPI client library that focused on multi request from OP.GG

172.6k](/packages/opgg-riotquest)[rap2hpoutre/jacky

Opinionated REST JSON HTTP API client for laravel

174.4k](/packages/rap2hpoutre-jacky)

PHPackages © 2026

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