The Nuxed Http Server component provides a simple to use Http Server.
This package can be installed with Composer.
$ composer require nuxed/http-server
use namespace Nuxed\Http\Server;
use namespace Nuxed\Http\Server\Socket;
use namespace Nuxed\Http\Message;
<<__EntryPoint>>
async function main(): Awaitable<void> {
$options = Server\Options::create();
$socket = await Socket\Server::listen(
Socket\SocketAddress::create('tcp://127.0.0.1:8000')
);
$handler = Server\ch(async($request) ==> {
$response = Message\Response\text('Hello, World!');
$response = $response->withCookie('foo', Message\cookie('bar'));
return $response;
});
$server = new Server\Server($options, $handler);
$server->listen($socket);
await $server->run();
}
For information on reporting security vulnerabilities in Nuxed, see SECURITY.md.
Nuxed is open-sourced software licensed under the MIT-licensed.