PHP code example of capmousse / react-restify

1. Go to this page and download the library: Download capmousse/react-restify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

capmousse / react-restify example snippets

 php
erver = new CapMousse\ReactRestify\Server("MyAPP", "0.0.0.1");

// Middleware
$server->use(function ($request, $next) {
	print_r($request->getMethod());
	$next();
});

// Dependency injection
$server->add(\Foo\Bar::class)

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

    $bar->foobar();
});

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

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) {
        $foo->bar();
        $response->end()
    }
}

$server->add(Foo::class);

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

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