PHPackages                             guide42/ochenta - 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. guide42/ochenta

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

guide42/ochenta
===============

HTTP request/response implementation

v0.6.0(6y ago)023ISCPHPPHP &gt;=7.2

Since Aug 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/guide42/ochenta)[ Packagist](https://packagist.org/packages/guide42/ochenta)[ RSS](/packages/guide42-ochenta/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

Ochenta: HTTP library
=====================

[](#ochenta-http-library)

- HTTP abstractions: use request/response objects instead of superglobals.
- HTTP middlewares: intersect the process of creating a response from a request.
- HTTP responders: actionable views that build responses.

Hello World
-----------

[](#hello-world)

```
use ochenta\ServerRequest;
use function ochenta\{emit, responder_of};

emit(new ServerRequest, responder_of('Hello World'));
```

Interested? Keep reading.

Usage
-----

[](#usage)

```
$req = new ServerRequest;
```

It could also be created with it's defaults values:

```
$req = new ServerRequest($_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, fopen('php://input', 'rb'));
```

That's a incoming request.
Superglobals are available as `$req->getQuery()`, `$req->getParsedBody()` and `$req->getFiles()`.

Then the low-level `Request` abstraction provides many more methods:

- `$req->getMethod()` and `$req->getTarget()` from the request line.
- `$req->getHeaders()` to get all headers and `$req->getHost()` for the normalized domain.
- `$req->getMediaType()` and `$req->getCharset()` from the `Content-Type` header.
- `$req->getAccept*()` returns the parsed Accept\* headers.

There is also `Response` object, but the response will be given by a responder.

Responders
----------

[](#responders)

When working in SAPI environment, you could define a response with a responder:

```
function hola(ServerRequest $req, callable $open) {
    $name = $req->getQuery()['name'] ?? 'World';
    $open(200, ['Content-Language' => ['en', 'es']]);
    yield "Hola $name";
}
```

Or using `ochenta\Response` wrapper:

```
function hola(ServerRequest $req, callable $open) {
    $name = $req->getQuery()['name'] ?? 'World';
    $res = new Response(200, ['Content-Language' => ['en', 'es']], "Hola $name");
    return responder_of($response)($req, $open);
}
```

Using a `ochenta\emit` function, the responder could be emitted:

```
emit(new ServerRequest, @hola);
```

Middlewares
-----------

[](#middlewares)

Use them to wrap your `request -> responder` process. This is what it look like:

```
function timeit(callable $handler): callable {
    return function(ServerRequest $req, callable $open) use($handler) {
        $time = -microtime(TRUE);
        $res = yield from $handler($req, $open);
        $time += microtime(TRUE);
        yield sprintf("%.7F secs", $time);
        return $res;
    };
}
```

Decorating your app responder:

```
$app = @hola;
$app = timeit($app);

emit(new ServerRequest, $app);
```

When options are needed, could be wrapped in yet another function.

```
function add_header(string $name, string $value): callable {
    return function(callable $handler) use($name, $value): callable {
        return function(ServerRequest $req, callable $open) use($name, $value, $handler) {
            return $handler($req, function(int $status, array $headers) use($name, $value, $open) {
                $headers[$name] = [$value];
                $open($status, $headers);
            });
        };
    };
}
```

Complex? This middleware exists at `ochenta\header`. This is how to use it:

```
$app = add_header('X-Frame-Options', 'SAMEORIGIN')($app);
```

What a hassle! Better use `ochenta\stack` to do stacks of middlewares:

```
$app = stack(@hola, [
    add_header('X-Xss-Protection', '1; mode=block'),
    add_header('X-Frame-Options', 'SAMEORIGIN'),
    @timeit,
]);
```

You got this far. Look at [example.php](example.php) to see the complete code.

API
---

[](#api)

```
responder_of(Response $resource)                             // creates a responder from a Response
responder_of(resource $resource)                             // ... from a resource
responder_of(scalar $resource)                               // ... from content

emit(ServerRequest $req, callable $handler)                  // emits a responder

stack(callable $responder, array $stack)                     // expects stack items to be a function(callable $next)
stack(callable $responder, callable $resolver, array $stack) // ... use resolver as function(callable $prev, $handler)

// MIDDLEWARES

header(string $name, array $values)                          // adds a header to responder
header(string $name, string $value)                          // ... with single value

cookie(Cookie $cookie)                                       // sets cookie into responder

append(string $content)                                      // adds content before body
append(string $content, string $tag)                         // ... before every given tag

// RESPONDERS

redirect(string $uri)                                        // redirect to the given url
redirect(string $uri, int $statusCode)                       // ... with given status code

// CONTENT NEGOTATION

accept\mediatypes(Request $req, array $available)            // negotiate media types
accept\charsets(Request $req, array $available)              // ... charsets
accept\encodings(Request $req, array $available)             // ... encodings
accept\languages(Request $req, array $available)             // ... languages

// HELPERS

stream_of(scalar $resource)                                  // creates tmp file with $resouce content
```

Badges
------

[](#badges)

[![Latest Stable Version](https://camo.githubusercontent.com/898456840e9459db52abd0a8cf74d4099be96f368ee404aefb89ba7ceb3db471/68747470733a2f2f706f7365722e707567782e6f72672f677569646534322f6f6368656e74612f762f737461626c652e737667)](https://packagist.org/packages/guide42/ochenta)[![Build Status](https://camo.githubusercontent.com/2c0690307306e3dccf1b4f78572aee788d1e1a2b82851e5237e1fcb2a86f0906/68747470733a2f2f7472617669732d63692e6f72672f677569646534322f6f6368656e74612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/guide42/ochenta)[![Coverage Status](https://camo.githubusercontent.com/e14e35e1ee79d84a085443d673f2694fdfb596a93391d637094bc008f7f19526/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f677569646534322f6f6368656e74612f62616467652e737667)](https://coveralls.io/github/guide42/ochenta)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Recently: every ~149 days

Total

9

Last Release

2212d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.0

v0.3.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![jm42](https://avatars.githubusercontent.com/u/3297150?v=4)](https://github.com/jm42 "jm42 (285 commits)")

---

Tags

httpmiddlewarerequestresponderresponse

### Embed Badge

![Health badge](/badges/guide42-ochenta/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.6k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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