HTTP plugin for Folk — accepts connections via hyper and dispatches requests to PHP workers.
Status: in active development. See folk-spec for the roadmap.
- Rust 1.85+
- folk-api (only dependency for plugin compilation)
# Cargo.toml
folk-plugin-http = "0.1"- Add the plugin to
folk.build.toml:
[build]
output = "my-folk"
[[plugin]]
crate_name = "folk-plugin-http"
version = "0.1"
config_key = "http"- Configure in
folk.toml:
[http]
listen = "0.0.0.0:8080"
read_timeout = "10s"
write_timeout = "30s"- Write a PHP handler:
<?php
// app/Http/FolkHandler.php
use Folk\Sdk\Http\HttpModeHandler;
use Folk\Sdk\Http\HttpRequest;
use Folk\Sdk\Http\HttpResponse;
class FolkHandler implements HttpModeHandler
{
public function handle(HttpRequest $request): HttpResponse
{
$response = new HttpResponse();
$response->status = 200;
$response->headers = ['Content-Type' => 'text/plain'];
$response->body = 'Hello from Folk!';
return $response;
}
}- Build and run:
folk-builder build
./my-folk serve
curl http://localhost:8080/
# Hello from Folk!No manual handler setup needed — folk-laravel registers LaravelHttpHandler automatically. All your Laravel routes, middleware, and controllers work out of the box:
// routes/web.php — works as-is
Route::get('/ping', fn () => response()->json(['status' => 'ok']));
Route::get('/user/{name}', fn (string $name) => response()->json(['hello' => $name]));State is reset between requests (auth, DB transactions, events, queue) via built-in resetters.
For latency-sensitive workloads, use runtime = "fork" in [server] to skip framework bootstrap per worker.
[http]
listen = "0.0.0.0:8080"
read_timeout = "10s"
write_timeout = "30s"| Key | Type | Default | Description |
|---|---|---|---|
listen |
SocketAddr |
"0.0.0.0:8080" |
Address and port to bind. |
read_timeout |
Duration |
"10s" |
Maximum time to read the request body. |
write_timeout |
Duration |
"30s" |
Maximum time to write the response. |
Duration format: "10s", "5m", "1h", "500ms".
The plugin starts a hyper HTTP/1.1 server on the configured address. For each incoming request:
- Encode — The request (method, URI, headers, body) is serialized to MessagePack as an
HttpRequestPayload. - Dispatch — The payload is sent to a PHP worker via
executor.execute(). - Decode — The worker returns a MessagePack-encoded
HttpResponsePayload(status, headers, body), which is converted back to an HTTP response.
Error responses:
- Encode failure →
500 - Worker error →
502 - Decode failure →
500
The plugin exposes one RPC method, http.connections, which reports the current active connection count via the admin socket.
PHP-side handler registration happens through folk-sdk's WorkerLoop::registerHttpHandler(), which binds to the http.handle RPC method automatically.
MIT