Create RESTful API with ReactPHP

1.1.1 2017-03-21 13:43 UTC

This package is not auto-updated.

Last update: 2022-08-04 05:16:44 UTC


Scrutinizer Code Quality

RESTful api made easy for ReactPHP, seriously.


Via composer

    $ composer require capmousse/react-restify

Create server

Here is an exemple of a simple HTTP server replying to all get call like

require 'vendor/autoload.php';

$server = new CapMousse\ReactRestify\Server("MyAPP", "");

// Middleware
$server->use(function ($request, $next) {

// Dependency injection

$server->get('/hello/{name}', function ($request, $response, \Foo\Bar $bar, $name) {
    	->write("Hello {$name}")



To create a secure HTTPS server, you need to give all your cert files to the server :

$server->listen(1337, "[::1]", [
    'local_cert' => __DIR__ . 'localhost.pem'

More examples can be found on the example directory like the Todo example.

Controller, Middleware and Dependency injection

React-Restify support Controller call, middleware à la express and Dependency Injection.

use CapMousse\ReactRestify\Http\Request;
use CapMousse\ReactRestify\Http\Response;

class Foo {
    public function bar() {
        echo "Do something";

class FooBar {
    public function baz (Response $response, Foo $foo) {


$server->use(function ($request, $next) {
    echo $request->httpRequest->getPath();

$server->get('/', 'FooBar@baz');

Design goals

React-Restify was primary made to build RESTful api easily. It can be used like Silex or Express.

Next part will be to support Sockets, Upgrade Requests... to create a real time API server.


MIT, see LICENCE file