reactorx/reactorx

dev-master 2024-01-07 15:20 UTC

This package is not auto-updated.

Last update: 2024-04-13 22:20:07 UTC


README

68747470733a2f2f6d656469612e74656e6f722e636f6d2f644c5a34635139314d526741414141432f696d2d776f726b696e672d6f6e2d69742d7374616e2d6d617273682e676966

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