Eio HTTP server with static file serving and route handlers
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add READMEs for 16 packages, fix merlint issues, add KVN tests

READMEs for all new packages. Fix missing docs (ocm, stix, globe),
naming (project_visible→visible, label_info→info, shader_kind→kind),
add .ocamlformat to csvt, add 11 KVN tests.

+42
+42
README.md
··· 1 + # respond 2 + 3 + Eio HTTP server with static file serving and route handlers. 4 + 5 + Serves files from a document root with MIME detection, ETag conditional requests, and directory index. Supports custom route handlers for API endpoints. Reuses HTTP types from the `requests` library. 6 + 7 + ## Installation 8 + 9 + ``` 10 + opam install respond 11 + ``` 12 + 13 + ## Usage 14 + 15 + ```ocaml 16 + Eio_main.run @@ fun env -> 17 + let routes = 18 + [ 19 + ("/api/health", fun _params -> Respond.Response.json {|{"ok":true}|}); 20 + ("/api/echo", fun params -> 21 + match List.assoc_opt "msg" params with 22 + | Some msg -> Respond.Response.text msg 23 + | None -> Respond.Response.bad_request "missing msg"); 24 + ] 25 + in 26 + Respond.run ~net:(Eio.Stdenv.net env) ~port:8080 27 + ~root:(Eio.Stdenv.cwd env) ~routes 28 + ``` 29 + 30 + ## API Overview 31 + 32 + - **`type route`** -- `string * (params -> Response.t)` -- path pattern + handler 33 + - **`type params`** -- `(string * string) list` -- query/route parameters 34 + - **`Response.json`**, **`Response.text`**, **`Response.html`** -- Response constructors 35 + - **`Response.not_found`**, **`Response.bad_request`**, **`Response.redirect`** -- Error responses 36 + - **`parse_url`** -- Extract path and query parameters 37 + - **`match_route`** -- Find matching route for a request path 38 + - **`run`** -- Start serving on a port with static files + route handlers 39 + 40 + ## License 41 + 42 + ISC