ReactorX
1.0.0
Install the project with composer
composer require reactorx/reactorx:dev-masterCreate an entry file, configure and start the server
<?php
use ReactorXHttpKernel;
use ReactorXHttpKernelConfiguration;
// Don't forget the autoloader
require_once __DIR__ . '/vendor/autoload.php';
$config = new HttpKernelConfiguration(
// Scan the classes in the "./src" directory
projectDir: __DIR__ . "/src"
);
// Create the server and pass it the configuration
$server = HttpKernel::createServer($config);
$server->run();Anywhere in the src directory, create a PingController.php class.
The startup process will automatically pick up the class and register it in the DI container as a controller.
<?php
use ReactorXAttributes{Controller, HttpGet};
use ReactHttpMessageResponse;
#[Controller]
final class PingController
{
#[HttpGet("ping")]
public final function ping(): Response
{
return new Response(
200,
['Content-Type' => 'text/plain'],
"pong"
);
}
}Now sending a request to /ping should respond with "pong"
GET http://localhost:3000/ping