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

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

thomseddon/http
===============

Beautifully simple PHP HTTP client inspired by node's superagent

21.6kPHP

Since Jul 8Pushed 11y ago1 watchersCompare

[ Source](https://github.com/thomseddon/http)[ Packagist](https://packagist.org/packages/thomseddon/http)[ RSS](/packages/thomseddon-http/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

HTTP [![Build Status](https://camo.githubusercontent.com/3dee29366de0497a49f85cb9a597f305823af05b09cb5f7eb78fa81cf453b637/68747470733a2f2f7472617669732d63692e6f72672f74686f6d736564646f6e2f687474702e737667)](https://travis-ci.org/thomseddon/http)
=====================================================================================================================================================================================================================================================

[](#http-)

Beautifully simple PHP HTTP client inspired by node's [superagent](https://github.com/visionmedia/superagent).

*Consider this a beta release*

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

[](#installation)

Download manually or via composer:

```
composer.phar require thomseddon/http:dev-master

```

Then require

```
# Autoload
require_once 'vendor/autoload.php'

# Or manually
require_once '/path/to/vendor/thomseddon/http/lib/HTTP.php'

```

Examples
--------

[](#examples)

### GET

[](#get)

```
require_once '/path/to/vendor/thomseddon/http/lib/HTTP.php'

$res = HTTP::get('http://httpbin.org/status/418')->send();

var_dump($res->error());
var_dump($res->status());
var_dump($res->body());
```

Prints:

```
bool(false)
int(418)
string(135) "
    -=[ teapot ]=-

       _...._
     .'  _ _ `.
    | ."` ^ `". _,
    \_;`"---"`|//
      |       ;/
      \_     _/
        `"""`
"

```

### POST JSON

[](#post-json)

```
require_once '/path/to/vendor/thomseddon/http/lib/HTTP.php'

$res = HTTP::post('http://httpbin.org/post')->json(array(
  'doing' => 'post'
))->send();

var_dump($res->status());
var_dump($res->body());
```

Prints

```

int(200)
class stdClass#3 (8) {
  ...
  public $json =>
  class stdClass#8 (1) {
    public $doing =>
    string(4) "post"
  }
  ...
}

```

API
---

[](#api)

### HTTP

[](#http)

#### HTTP::get(string $url)

[](#httpgetstring-url)

Return an HTTP\_Request instance with method set to `GET`

#### HTTP::post(string $url)

[](#httppoststring-url)

Return an HTTP\_Request instance with method set to `POST`

#### HTTP::put(string $url)

[](#httpputstring-url)

Return an HTTP\_Request instance with method set to `PUT`

#### HTTP::del(string $url)

[](#httpdelstring-url)

Return an HTTP\_Request instance with method set to `DELETE`

#### HTTP::configure(array $config)

[](#httpconfigurearray-config)

Two keys can be set:

- `base` *string* - This string will be prepended to all `url`'s during `send()`
- `headers` *array* - Array of headers that will be sent with all subsequent requests

```
HTTP::configure(array(
  'base' => 'http://api.mysite.com/v1',
  'headers' => array(
    'User-Agent' => 'Frontend Service (0.1)'
  )
));

HTTP::get('/status'); // GET's http://api.mysite.com/v1/status
```

#### HTTP::on(string $event, function $handler)

[](#httponstring-event-function-handler)

Add an handler that will be called when `$event` occurs

#### HTTP::emit(string $event, mixed $data = null)

[](#httpemitstring-event-mixed-data--null)

Emit an event, `$data` will be passed to any handlers as the first argument

### HTTP\_Request

[](#http_request)

All methods (except send) return the `$this` and so can be chained for extra fun.

#### method(string $method)

[](#methodstring-method)

Set HTTP method

#### url(string $url)

[](#urlstring-url)

Set URL

#### set(mixed $data, mixed $value = false)

[](#setmixed-data-mixed-value--false)

Set headers, the following are equivalent:

```
HTTP::get('http://google.com')->set(array(
  'User-Agent' => 'My Service (0.1)'
));
HTTP::get('http://google.com')->set('User-Agent', 'My Service (0.1)');
HTTP::get('http://google.com')->set('User-Agent: My Service (0.1)');
```

#### query(array $query)

[](#queryarray-query)

Set query params, expects `key => value` array

#### json(mixed $data)

[](#jsonmixed-data)

Set's json body: `json_encodes` data and sets `Content-Type` and `Content-Length` headers

#### attach(mixed $files, $path = null)

[](#attachmixed-files-path--null)

Attach a file, the following are equivalent:

```
HTTP::post('http://uploads.com')->attach(array(
  'cat' => '/cats/large.png'
));
HTTP::post('http://uploads.com')->attach('cat', '/cats/large.png');
```

#### send()

[](#send)

Sends the request, returns a `HTTP_Response`

### HTTP Response

[](#http-response)

#### error()

[](#error)

`bool` indicated if the request was not successful

#### status()

[](#status)

HTTP status code

#### body()

[](#body)

Response body

Testing
-------

[](#testing)

```
phpunit

```

Author
------

[](#author)

[Thom Seddon](https://twitter.com/ThomSeddon)

License
-------

[](#license)

The MIT License

Copyright (c) 2014 Thom Seddon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/96ecf519c9ed6c657769399f8c12e4f6f665a6541b162219b4928ec56adad779?d=identicon)[thomseddon](/maintainers/thomseddon)

---

Top Contributors

[![thomseddon](https://avatars.githubusercontent.com/u/747138?v=4)](https://github.com/thomseddon "thomseddon (8 commits)")

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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