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

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

legionth/http-rest
==================

REST HTTP-Server on top of ReactPHP

v0.3.0(7y ago)031[1 PRs](https://github.com/legionth/reactphp-http-rest/pulls)MITPHP

Since Nov 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/legionth/reactphp-http-rest)[ Packagist](https://packagist.org/packages/legionth/http-rest)[ RSS](/packages/legionth-http-rest/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (2)Versions (8)Used By (0)

REST HTTP Server
================

[](#rest-http-server)

Creating [ReactPHP HTTP Server](https://github.com/reactphp/http) but with REST

**Table of Contents**

- [Example](#example)
- [Usage](#usage)
    - [Server](#server)
    - [Dynamic Values](#dynamic-values)
    - [Default Callback](#default-callback)
    - [Parameter Placeholder](#parameter-placholder)
- [Install](#install)
- [License](#license)

Example
-------

[](#example)

This is an HTTP server which responds with an `hello`in every request on `/say/hello`.

Every other call will result in an 404 response.

```
$loop = \React\EventLoop\Factory::create();

$server = new \Legionth\React\Http\Rest\Server();

$server->get('/say/hello', function (\Psr\Http\Message\ServerRequestInterface $request, callable $next) {
    return new \React\Http\Response(200, array(), 'hello');
});

$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0', $loop);
$server->listen($socket);

$loop->run();
```

Make sure the callback function has 2 parameters. The first parameter is always the PSR-7 request object. The second parameter is the next endpoint defined in your API. If no next function is given it will be the default function of the server which will respond with will create an 404 error by default.

Usage
-----

[](#usage)

### Server

[](#server)

The `Server` uses the [ReactPHP HTTP Server](https://github.com/reactphp/http) and uses its internal implemented [middleware](https://github.com/reactphp/http#middleware)

Every endpoint is added as a middleware, therefor a request will pass every function sequentially. The second parameter (defined as `$next` in these examples) can be used to pass the request to following endpoint.

### Dynamic Values

[](#dynamic-values)

To add dynamic values in the REST API definition the operator `:` can be used

```
$server->post('/say/:word', function (\Psr\Http\Message\ServerRequestInterface $request, callable $next, array $parameters) {
    $word = $parameters['word'];

    return new \React\Http\Response(200, array(), 'You said: ' . $word);
});
```

Now a HTTP client can call the address e.g. `http://localhost:8080/say/hello`. The key `word` and value `hello` will be stored in the third parameter of the callback function.

There is no type check her that can validate which API should be used. `/say/:word` and`/say/:number` would be the same. In this case the order of your API definition matters.

### Default Callback

[](#default-callback)

A default callback can be defined in the `listen` method. This method will be used if no definition can be found.

By default this library will respond with an `404` HTTP response.

### Parameter Placeholder

[](#parameter-placeholder)

As seen in the previous chapter you can use the `:` to mark dynamic values. Instead of using this strategy, to mark dynamic parameters, this library supports additional strategies via different classes:

- `/to/path/:paramter` - `Legionth\React\Http\Rest\Paramaters\Label\Colon`
- `/to/path/[paramter]` - `Legionth\React\Http\Rest\Paramaters\Label\CurlyBracket`
- `/to/path/{paramter}` - `Legionth\React\Http\Rest\Paramaters\Label\SquareBrackets`

Checkout the examples for more information.

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This will install the latest supported version:

```
$ composer require legionth/http-rest:^0.2
```

License
-------

[](#license)

MIT

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

4

Last Release

2693d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1578709?v=4)[Niels Theen](/maintainers/legionth)[@legionth](https://github.com/legionth)

---

Top Contributors

[![legionth](https://avatars.githubusercontent.com/u/1578709?v=4)](https://github.com/legionth "legionth (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.1k337.6k1](/packages/ccxt-ccxt)[discord-php/http

Handles HTTP requests to Discord servers

24345.9k11](/packages/discord-php-http)[clue/soap-react

Simple, async SOAP webservice client library, built on top of ReactPHP

64121.9k2](/packages/clue-soap-react)[rx/websocket

Websockets for PHP using Rx

34182.4k2](/packages/rx-websocket)[php-http/react-adapter

React HTTP Adapter

19263.7k4](/packages/php-http-react-adapter)[voryx/websocketmiddleware

WebSocket Middleware for React

2669.4k3](/packages/voryx-websocketmiddleware)

PHPackages © 2026

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