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

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

phpixie/http
============

HTTP library for PHPixie, implements the PSR-7 standard

3.2(3y ago)1823.0k35BSD-3-ClausePHP

Since Oct 11Pushed 3y ago5 watchersCompare

[ Source](https://github.com/PHPixie/HTTP)[ Packagist](https://packagist.org/packages/phpixie/http)[ Docs](http://phpixie.com)[ RSS](/packages/phpixie-http/feed)WikiDiscussions master Synced yesterday

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

HTTP
====

[](#http)

PHPixie HTTP library

[![Build Status](https://camo.githubusercontent.com/3283387a50f9f629791846dbbf3fcccc810e038702c2f39a4497e9a7167c9d44/68747470733a2f2f7472617669732d63692e6f72672f504850697869652f485454502e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/PHPixie/HTTP)[![Test Coverage](https://camo.githubusercontent.com/75413baa5aa70f6be17455cf2bbb3fc190361f618ed12b33a2cf5de4926b1d1b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f504850697869652f485454502f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/PHPixie/HTTP)[![Code Climate](https://camo.githubusercontent.com/f5d9df537ee8c7dd5534a05ce3bf53ffd0467e61932714842cb00c1a69a67477/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f504850697869652f485454502f6261646765732f6770612e737667)](https://codeclimate.com/github/PHPixie/HTTP)[![HHVM Status](https://camo.githubusercontent.com/a796f98c7d383eceabe284e1fc1b613fc20b3d443551f6210dd84547fcb19283/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f706870697869652f687474702e7376673f7374796c653d666c61742d737175617265)](http://hhvm.h4cc.de/package/phpixie/http)

[![Author](https://camo.githubusercontent.com/24a0a94bb83eb81ba03c32074967dc730174cfd2849e984169db461d955cdbb9/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d40647261636f6e792d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/dracony)[![Source Code](https://camo.githubusercontent.com/e8f30c9ed4ed0dc2686e08d9d91c9b3606feea894be2cb81342c6f270abc6ee4/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d706870697869652f687474702d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpixie/http)[![Software License](https://camo.githubusercontent.com/b60331a2084501dc07cf6d6964c0da58dd005d89c45cf3b28b4b22b60f5ec00f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpixie/http/blob/master/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/23cd2944fdfd1b59a3f2048f552580605c5397e045d805b4ab50afb140646fd6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706870697869652f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpixie/http)

This library handles HTTP protocol asbtraction and implements the PSR-7 implemenetation. In addition to implementing the standard it provides wrappers for Requests and Responses and also abstractions for Cookies and Session. Since these wrappers work with any PSR-7 implementation it will now be possible to run PHPixie in some interesting environments, like inside ReactPHP etc. You can also use these abstractions to create your own PSR-7 compatible microframework.

Here is a quick demo:

```
//Without the PHPixie Framework
$slice = new \PHPixie\Slice();
$http = new \PHPixie\HTTP($slice);

//inside the framework
$http = $frameworkBuilder->components()->http();
```

**Requests**

```
//Build a Request from globals ($_GET etc)
$request = $http->request();

//Or you can pass a PSR-7 ServerRequestInterface to wrap
$request = $http->request($serverRequest);

//$_GET
$query = $request->query();

//$_POST
$query = $request->data();

//Additional attributes,
//e.g. parameters from routing
$query = $request->attributes();

//$_GET['pixie']
$query->get('pixie');

//With default value
$query->get('pixie', 'Trixie');

//Throw an exception if field is not set
$query->getRequired('pixie');

//$_GET['user']['name'];
$query->get('user.name');

//Or like this
$userData = $query->slice('user');
$userData->get('name');

//In this case $userData
//is an instance of \PHPixie\Slice\Data
//totally unrelated to HTTP library
//so you can pass it around the system
//without coupling to HTTP

//Accessing $_SERVER
$request->server()->get('http_host');

//Get a header line
//If multiple values are present
//for the same header, they will be
//concatenated with ','
$request->headers()->get('host');
$request->headers()->getRequired('host');

//Get header values as array
$request->headers()->getLines('accept');

//Handling uploads
$uploadedFile = $request->uploads()->get('file');
$uploadedFile->move('/images/fairy.png');

//HTTP method
$uri = $request->method();

//Accessing Uri
$uri = $request->uri();
$path = $uri->getPath();

//Underlying ServerRequest
$serverRequest = $request->serverRequest();
```

**Response**
Apart from provideing a Response wrapper, PHPixie HTTP also can simplify building some frequently used responses, like JSON responses with proper headers and file downloads.

```
$responses = $http->responses();

//The simplest response
$response = $responses->string('hello world');

//JSON with headers that forbid caching
$responses->json(array('name' => 'Pixie'));

//Redirect
$responses->redirect('http://phpixie.com/');

//File streaming
$responses->streamFile('pixie.png');

//Download contetnts as a file
//useful for CSV, TXT types
$responses->download('name.txt', 'text/plain', 'Trixie');

//File download
$responses->downloadFile('pixie.png', 'image.png', 'images/fairy.png');

//Modifying the status code
$response->setStatus('404', 'Not Found');

//OR you can omit the phrase to use
//the default one for the provided code
$response->setStatus('404');

//Modifying headers
$response->headers->set('Content-Type', 'text/csv');

//Transforming into PSR-7 Response
$response->asResponseMessage();

//Outputting a response
$http->output($response);
```

**Context**
Another important part is managing users Cookies and Session. Frequently you would access them outside of the request processing, for example in you authroization library. Also for non0standard environments, like in ReactPHP you would need special handlers for modifying the session. That’s why PHPixie separates these into a Context instance. You can store it separately, allowing users to modify cookies independently and then merge them with the Response. It’s rather easy:

```
//Generate context for a particular request
$context = $http->context($request);

//And then it's pretty straightforward
$cookies = $context->cookies();
$session = $context->session();

$cookies->set('lang', 'en');
$session->getRequired('user_id');

//Remember to pass the context
//when outputting the Response
//or generation a PSR-7 response
$http->output($response, $context);
$response->asResponseMessage($context);
```

To obtain the HTTP Context when using the PHPixie framework, you need to get it from the framework context:

```
$httpContext = $frameworkBuilder->context()->httpContext();
$cookies = $httpContext->cookies();
$session = $httpContext->session();
```

Also you can just use the PSR-7 implementations without PHPixie wrappers:

```
//Get the PSR-7 factory
$psr7 = $http->messages();
$serverRequest = $psr7->sapiServerRequest();
```

As all the other PHPixie libraries it is 100% unit tested and has a high codeclimate score (actually perfect score in this case)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 91.5% 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 ~535 days

Recently: every ~666 days

Total

6

Last Release

1241d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fd2ee997c779cf774247d3d4cde7d90491484f817032aab6dbc314857973b36?d=identicon)[dracony](/maintainers/dracony)

---

Top Contributors

[![dracony](https://avatars.githubusercontent.com/u/3127080?v=4)](https://github.com/dracony "dracony (43 commits)")[![rez1dent3](https://avatars.githubusercontent.com/u/5111255?v=4)](https://github.com/rez1dent3 "rez1dent3 (2 commits)")[![dorantor](https://avatars.githubusercontent.com/u/391611?v=4)](https://github.com/dorantor "dorantor (1 commits)")[![vmeling](https://avatars.githubusercontent.com/u/27155325?v=4)](https://github.com/vmeling "vmeling (1 commits)")

---

Tags

httppsr-7

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

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

PSR HTTP message bridge

1.3k320.9M982](/packages/symfony-psr-http-message-bridge)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

539238.7M44](/packages/league-uri-interfaces)[mezzio/mezzio

PSR-15 Middleware Microframework

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

PSR-7 middleware foundation for building and dispatching middleware pipelines

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

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

185702.8k43](/packages/laudis-neo4j-php-client)

PHPackages © 2026

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