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

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

sfn/httpclient
==============

A simple PSR-7 client

v0.1.1(8y ago)222MITPHPPHP ^7.0

Since Aug 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/sfn/psr7-httpclient)[ Packagist](https://packagist.org/packages/sfn/httpclient)[ Docs](https://github.com/sfn/psr7-httpclient)[ RSS](/packages/sfn-httpclient/feed)WikiDiscussions master Synced yesterday

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

Sfn HttpClient
==============

[](#sfn-httpclient)

[![Latest Version](https://camo.githubusercontent.com/6e9e4bbf658a65a83bb6db38a098fddf3aa8f2d230742579d3e62d655059645f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73666e2f68747470636c69656e742e737667)](https://packagist.org/packages/sfn/httpclient)[![MIT license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/sfn/psr7-httpclient/master/LICENSE)[![PHP](https://camo.githubusercontent.com/4439ef8bb8b9318814dc11a629970c650200231f5e5e73aff3e463417d4b4c1e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302532422d3737376262342e737667)](http://www.php.net/)

Just a simple and little PSR7 client. It is still a work-in-progress but, more or less, it works.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
    - [Zend Diactoros support](#zend-diactoros-support)
    - [Guzzle support](#guzzle-support)
    - [Slim support](#slim-support)
- [Usage](#usage)
    - [Create a client instance](#create-a-client-instance)
    - [Send a request](#send-a-request)
    - [Methods for REST API](#helper-methods-for-rest-api)
    - [Base URI](#base-uri)
- [To-do](#to-do)
- [License](#license)

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

[](#requirements)

- PHP 7.0 or higher
- `php-curl` or `allow_url_fopen` set to true
- A [PSR7](http://www.php-fig.org/psr/psr-7/) implementation.

`Sfn\HttpClient` needs a PSR-7 implementation. It supports [Zend Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7) and [Slim](https://github.com/slimphp/Slim-Http) at the moment.

Of course you can write your own HTTP Factory implementation for any PSR-7 implementation, look [here](https://github.com/http-interop/http-factory-diactoros/tree/master/src)for PSR-17 Http Factory interfaces.

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

[](#installation)

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

```
composer require sfn/httpclient

```

#### Zend Diactoros support

[](#zend-diactoros-support)

```
composer require http-interop/http-factory-diactoros

```

#### Guzzle support

[](#guzzle-support)

```
composer require http-interop/http-factory-guzzle

```

#### Slim support

[](#slim-support)

```
composer require http-interop/http-factory-slim

```

Usage
-----

[](#usage)

### Create a client instance

[](#create-a-client-instance)

With the `ClientFactory::make()` method you can create the correct instance of the client. If it finds curl installed, it creates a client with a curl backend, otherwise it create a client who send request via php's `file_get_contents`.

`ClientFactory::make()` accepts an associative array with the client configuration. You must specify at least your PSR-17 HTTP Factory implementation. [Here](PARAMETERS.md#client-configuration-parameters) you can find the complete list of parameters in you can set in the configuration array.

```
// Zend Diactoros
$config = [
    'requestfactory'  => new Http\Factory\Diactoros\RequestFactory,
    'responsefactory' => new Http\Factory\Diactoros\ResponseFactory,
    'urifactory'      => new Http\Factory\Diactoros\UriFactory,
];

// Guzzle
$config = [
    'requestfactory'  => new Http\Factory\Guzzle\RequestFactory,
    'responsefactory' => new Http\Factory\Guzzle\ResponseFactory,
    'urifactory'      => new Http\Factory\Guzzle\UriFactory,
];

// Slim
$config = [
    'requestfactory'  => new Http\Factory\Slim\RequestFactory,
    'responsefactory' => new Http\Factory\Slim\ResponseFactory,
    'urifactory'      => new Http\Factory\Slim\UriFactory,
];

$client = Sfn\HttpClient\ClientFactory::make($config);
```

### Send a request

[](#send-a-request)

First of all, you must create a request with your preferred `Psr\Http\Message\RequestInterface` implementation. Then you simply call the `send()` method of the client.

```
$request = (new Zend\Diactoros\Request())
    ->withUri(new Zend\Diactoros\Uri('http://api.example.com/path'))
    ->withMethod('GET')
    ->withAddedHeader('Content-Type', 'application/json');

$response = $client->send($request); // Return a ResponseInterface
```

### Helper methods for REST API

[](#helper-methods-for-rest-api)

There are `get()`, `post()`, `put()`, `delete()` and `patch()` helper methods. You can pass a second parameter, with an array of options. [Here](PARAMETERS.md#request-parameters) you can find a complete list of request parameters.

```
// GET request
$response = $client->get('http://api.example.com/path');

// POST request
$response = $client->post(
    'http://api.example.com/path',
    ['body' => http_build_query(['foo' => 'bar'])]
);
```

### Base URI

[](#base-uri)

You can also specify a base uri in the client configuration.

```
$config = [
    'requestfactory'  => new Http\Factory\Diactoros\RequestFactory,
    'responsefactory' => new Http\Factory\Diactoros\ResponseFactory,
    'urifactory'      => new Http\Factory\Diactoros\UriFactory,
    'baseuri'         => 'http://api.example.com'
];
$client = Sfn\HttpClient\ClientFactory::make($config);

// GET request
$response = $client->get('path'); // GET http://api.example.com/path
```

To-Do
-----

[](#to-do)

- Cookies support
- SSL authentication
- Examples
- Better documentation

License
-------

[](#license)

[MIT License](LICENSE)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

3230d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1965485?v=4)[sfn](/maintainers/sfn)[@sfn](https://github.com/sfn)

---

Top Contributors

[![sfn](https://avatars.githubusercontent.com/u/1965485?v=4)](https://github.com/sfn "sfn (11 commits)")

---

Tags

http-clientphp7psr-17psr-7psr7-httpclientrest-apirest-clienthttppsr-7clientpsr-17

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B3.8k](/packages/guzzlehttp-psr7)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k320.9M942](/packages/symfony-psr-http-message-bridge)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28146.3k](/packages/phpro-http-tools)[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M120](/packages/mezzio-mezzio)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

587.2M96](/packages/laminas-laminas-stratigility)[laudis/neo4j-php-client

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

185671.3k42](/packages/laudis-neo4j-php-client)

PHPackages © 2026

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