reactorx / reactorx
dev-master
2024-01-07 15:20 UTC
Requires
- php-di/php-di: ^6.4
- react/event-loop: 1.3
- react/http: 1.8
- react/socket: ^1.12
This package is not auto-updated.
Last update: 2024-04-13 22:20:07 UTC
README
Installation
Install the project with composer
composer require reactorx/reactorx:dev-master
Create an entry file, configure and start the server
<?php use ReactorX\HttpKernel; use ReactorX\HttpKernelConfiguration; // 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();
Ping request example
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 ReactorX\Attributes\{Controller, HttpGet}; use React\Http\Message\Response; #[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