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

Abandoned → [windwalker/http](/?search=windwalker%2Fhttp)ArchivedLibrary[HTTP &amp; Networking](/categories/http)

asika/http
==========

PSR HTTP Message implementations. (PHP 5.3 Compatible)

1.0.2(9y ago)2658.4k↓50%24LGPL-2.0+PHPPHP &gt;=5.3.10

Since Aug 2Pushed 8y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (4)Versions (4)Used By (4)

The PSR7 Http Implementation [![Analytics](https://camo.githubusercontent.com/c068693f9110de626e635e3afeeef846de15f25a781e03c7d291592c595849e6/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d34383337323931372d312f687474702f726561646d65)](https://github.com/igrigorik/ga-beacon)
=======================================================================================================================================================================================================================================================================================================

[](#the-psr7-http-implementation---)

[![Build Status](https://camo.githubusercontent.com/e525c63042d020148d95f00e493c25725e1333f61a69c3aec7168743dc0df2d2/68747470733a2f2f7472617669732d63692e6f72672f6173696b6133323736342f687474702e737667)](https://travis-ci.org/asika32764/http)[![Latest Stable Version](https://camo.githubusercontent.com/bff796b0281805700d2984148cef3d577af40c405725779c278cdc0633dfea4a/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f687474702f762f737461626c65)](https://packagist.org/packages/asika/http)[![Total Downloads](https://camo.githubusercontent.com/684187d92554a7c5ba7b31d33be5ae27b1e281a134cb2e783728ab17d5842fb8/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f687474702f646f776e6c6f616473)](https://packagist.org/packages/asika/http)[![Latest Unstable Version](https://camo.githubusercontent.com/80de020e8cdc083ae2230b67744c8a7063770e5fa71fc16065bc84310691e247/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f687474702f762f756e737461626c65)](https://packagist.org/packages/asika/http)[![License](https://camo.githubusercontent.com/57cdc88f8f972fc76deb6e46cc9b71eb556a7db744d24334b87bb1150736b865/68747470733a2f2f706f7365722e707567782e6f72672f6173696b612f687474702f6c6963656e7365)](https://packagist.org/packages/asika/http)

This package provides PSR7 standard Http message objects, Uri objects, Stream objects and Client request object. **(PHP 5.3 Compatible)**

> Some parts of this package based on [phly/http](https://github.com/phly/http) and [joomla/http](https://github.com/joomla-framework/http)

**Project deprecated, please see [windwalker/http](https://github.com/ventoviro/windwalker-http)**

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this to the require block in your `composer.json`.

```
{
    "require": {
        "asika/http": "~1.0"
    }
}
```

Make A Request
--------------

[](#make-a-request)

HttpClient is a simple class to make restful request.

```
use Asika\Http\HttpClient;

$http = new HttpClient;

$response = $http->get('http://example.com/?foo=bar');

// This is PSR7 ResponseInterface
(string) $response->getBody();
```

### Other Methods

[](#other-methods)

```
$http = new HttpClient;

// The post data can be query string or array
$response = $http->post('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->put('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->patch('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->delete('http://example.com/?foo=bar', array('post_data' => 'data'));

$response = $http->head('http://example.com/?foo=bar');
$response = $http->trace('http://example.com/?foo=bar');
$response = $http->options('http://example.com/?foo=bar');

// With headers
$response = $http->get('http://example.com/', null, array('X-Foo' => 'Bar'));

// Use request()
$response = $http->request('POST', 'http://example.com/?foo=bar', 'this=is&post=data');
```

### Use Psr RequestInterface to Make Request

[](#use-psr-requestinterface-to-make-request)

Psr7 Request is a immutable object, you have to get the return object every operation.

```
use Asika\Http\Request;

$request = new Request;

// Note: You have to get the return value.
// Every change will return new object.
$request = $request->withRequestTarget('http://example.com/flower/sakura')
    ->withMethod('POST')
    ->withAddedHeader('Authorization', 'Bearer ' . $token)
    ->withAddedHeader('Content-Type', 'application/text');

// OR
$request = new Request(
    'http://example.com/flower/sakura',
    'POST',
    'php://memory',
    array(
        'Authorization' => 'Bearer ' . $token,
        'Content-Type'  => 'application/json',
    )
);

// This is a POST request so we write post data to body
$request->getBody()->write('this=is&post=data');

$http = new HttpClient;

// Send request
$response = $http->send($request);
```

Use Uri and Json output.

```
use Asika\Http\Request;
use Asika\Http\Uri\PsrUri;

$request = (new Request)
    ->withUri(new PsrUri('http://example.com'))
    ->withMethod('POST')
    ->withAddedHeader('Authorization', 'Bearer ' . $token)
    ->withAddedHeader('Content-Type', 'application/json') // Use JSON

    // Note: Request will ignore path and query in Uri
    // So we have to set RequestTarget here
    ->withRequestTarget('/path/of/uri?flower=sakura');

// If you want to set a non-origin-form request target, set the
// request-target explicitly:
$request = $request->withRequestTarget((string) $uri);       // absolute-form
$request = $request->withRequestTarget($uri->getAuthority(); // authority-form
$request = $request->withRequestTarget('*');                 // asterisk-form

// This is JSON request so we encode data here
$request->getBody()->write(json_encode($data));
$response = $http->send($request);

$response->getStatusCode(); // 200 is OK
```

### Custom Transports and Options

[](#custom-transports-and-options)

Now support Curl and Steam 2 transports.

```
use Asika\Http\Transport\CurlTransport;

$options = array(
    'certpath' => '/custom/cert.pem'
);

$transport = new CurlTransport($options);

// Set transport when client new
$http = new HttpClient(array(), $transport);
```

Set custom CURL options:

```
$options = array(
    'options' => array(
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_SSL_VERIFYPEER => true
    )
);

$httpOptions = array(
    'headers' => array(
        'X-Foo' => 'Bar'
    )
);

$http = new HttpClient($httpOptions, new CurlTransport($options));
```

### Download Remote File

[](#download-remote-file)

```
$http = new HttpClient;

$dest = '/path/to/local/file.zip';

$response = $http->download('http://example.com/file.zip', $dest);

if ($response->getStatusCode() != 200)
{
    // Error
}
```

### Response Interface

[](#response-interface)

Response object holds a Stream object to store returned string.

```
// The return value is: 'FOO BAR'
$body = $response->getBody();

// Simply to string
(string) $body; // FOO BAR

$body->seek(2);
$body->getContents(); // O BAR

$body->rewind();
$body->read(5); // FOO B

$body->getSize(); // 7
```

Uri
---

[](#uri)

`Uri` is a simple Uri object to modify URL but not Psr UriInterface.

The methods provided in the `Uri` class allow you to manipulate all aspects of a uri. For example, suppose you wanted to set a new uri, add in a port, and then also post a username and password to authenticate a .htaccess security file. You could use the following syntax:

```
// new uri object
$uri = new Asika\Http\Uri\Uri;

$uri->setHost('http://localhost');
$uri->setPort('8888');
$uri->setUser('myUser');
$uri->setPass('myPass');

echo $uri->__toString();
```

This will output:

```
myUser:myPass@http://localhost:8888

```

If you wanted to add a specific filepath after the host you could use the `setPath()` method:

```
// set path
$uri->setPath('path/to/file.php');
```

Which will output

```
myUser:myPass@http://localhost:8888path/to/file.php

```

Adding a URL query:

```
// url query
$uri->setQuery('foo=bar');
```

Output:

```
myUser:myPass@http://localhost:8888path/to/file.php?foo=bar

```

### PsrUri

[](#psruri)

`PsrUri` is a Uri object implemented the Psr UriInterface.

This object is also immutable, so we must get return value as new object every change.

```
$uri = (new PsrUri('http://example.com'))
    ->withScheme('https')
    ->withUserInfo('user', 'pass')
    ->withPath('/path/to/target')
    ->withQuery('flower=sakura')
    ->withFragment('#hash');

(string) $uri; // https://user:pass@example.com/path/to/target?flower=sakura#fragment
```

Stream
------

[](#stream)

Stream is a powerful stream wrapper.

Read write data to memory:

```
$stream = new Stream('php://memory', 'wb+');

$stream->write('Foo Bar');

$stream->rewind(); // Back to begin

// Now we take something we wrote into memory

$stream->__toString(); // get: Foo Bar

// OR

$stream->rewind();
$stream->getContents(); // get: Foo Bar
```

Read data from `php://input`

```
$stream = new PhpInputSteam;

$data = $stream->__toString(); // foo=bar

$query = \Asika\Http\Uri\UriHelper::parseQuery($data); // array('foo' => 'bar')
```

Read file:

```
$stream = new Stream('/path/to/file.txt', 'r+');

$stream->__toString(); // Read

$steam->seek($stream->getSize());
$steam->write('new string'); // Write
```

Quick copy stream.

```
// Remote source
$src = new Stream('http://example/test.txt');

// Local store
$dest = new Stream('/path/to/local/test.txt');

// Do copy
\Asika\Http\Helper\StreamHelper::copy($src, $dest);

// Get Data
$dest->rewind();
$data = $dest->getContents();
```

See: [Psr7 StreamInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#13-streams)/ [API](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#34-psrhttpmessagestreaminterface)

Other Http Message Objects
--------------------------

[](#other-http-message-objects)

### `ServerRequest`

[](#serverrequest)

A Request object to store server data, like: `$_SERVER`, `$_COOKIE`, `$_REQUEST` etc.

### `UploadedFile`

[](#uploadedfile)

An object to store uploaded files, see: [Uploaded files interface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#16-uploaded-files)

```
$files = array();

foreach ($_FILE as $name => $file)
{
    $files[$name] = new UploadedFile($file['tmp_name'], $file['size'], $file['error'], $file['name'], $file['type']);
}

$request = new ServerRequest(
  $_SERVER,
  $_GET,
  $_POST,
  $_COOKIE,
  $files
);
```

More About Psr 7
----------------

[](#more-about-psr-7)

[PSR7 HTTP message interfaces](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) / [HTTP Message Meta Document](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message-meta.md)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~150 days

Total

3

Last Release

3639d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (27 commits)")[![photodude](https://avatars.githubusercontent.com/u/10253980?v=4)](https://github.com/photodude "photodude (1 commits)")

---

Tags

http-clientpsr-uriinterfacepsr7-httpstreamurihttpresponserequeststreamuriclientpsr7restfulasika

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[pdeans/http

PSR-7 cURL HTTP client with support for PSR-17 HTTP factories.

1466.2k3](/packages/pdeans-http)[workerman/psr7

PSR-7 message implementation that also provides common utility methods

1079.8k10](/packages/workerman-psr7)[chillerlan/php-httpinterface

A PSR-7/17/18 http message/client implementation

1417.1k5](/packages/chillerlan-php-httpinterface)

PHPackages © 2026

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