folk-plugin-http
HTTP plugin for Folk — accepts connections via hyper and dispatches requests to PHP workers.
Status: in active development. See folk-spec for the roadmap.
Requirements
- Rust 1.85+
- folk-api (only dependency for plugin compilation)
Installation
# Cargo.toml
= { = "https://github.com/Folk-Project/folk-plugin-http" }
# Once published: folk-plugin-http = "0.1"
Quick start
- Add the plugin to
folk.build.toml:
[]
= "my-folk"
[[]]
= "folk_plugin_http"
= "https://github.com/Folk-Project/folk-plugin-http"
= "http"
- Configure in
folk.toml:
[]
= "0.0.0.0:8080"
= "10s"
= "30s"
- Write a PHP handler:
- Build and run:
# Hello from Folk!
For latency-sensitive workloads, use runtime = "fork" in [server] after installing folk-runtime-fork.
Configuration
| 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. |
How it works
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.
License
MIT