Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Feb 26, 2023
1 parent 7df79c1 commit b9fab57
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions README.md
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://github.com/innmind/async-http-server/workflows/CI/badge.svg?branch=main)](https://github.com/innmind/async-http-server/actions?query=workflow%3ACI)
[![Type Coverage](https://shepherd.dev/github/innmind/async-http-server/coverage.svg)](https://shepherd.dev/github/innmind/async-http-server)

Description
Experimental async HTTP server built on top of `Fiber`s.

## Installation

Expand All @@ -13,4 +13,48 @@ composer require innmind/async-http-server

## Usage

Todo
```php
# server.php
<?php
declare(strict_types=1);

require 'path/to/vendor/autoload.php';

use Innmind\Async\HttpServer\Main;
use Innmind\OperatingSystem\OperatingSystem;
use Innmind\Http\Message\{
ServerRequest,
Response,
StatusCode,
};
use Innmind\Filesystem\Name;
use Innmind\Url\Path;

new class extends Main {
protected static function handle(ServerRequest $request, OperatingSystem $os): Response
{
return $os
->filesystem()
->mount(Path::of('somewhere/'))
->get(Name::of('some-file'))
->match(
static fn($file) => new Response\Response(
StatusCode::ok,
$request->protocolVersion(),
null,
$file->content(),
),
static fn() => new Response\Response(
StatusCode::notFound,
$request->protocolVersion(),
),
);
}
};
```

You can run this server via the command `php server.php`. By default the server is exposed on the port `8080`.

This example will return the content of the file `somewhere/some-file` if it exists on the filesystem otherwise it will respond with a `404 not found`.

The asynchronicity of this program is handled by the `OperatingSystem` abstraction meaning you can write code _as if_ it was synchronous.

0 comments on commit b9fab57

Please sign in to comment.