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.

ocaml-respond: enable MDX on lib/respond.mli, harden doc example

The Quick Start example was a sketch that called [run] with free
[net]/[root] and used [...] ellipses inside the route handlers.
Replaced with a pure-helpers spec that exercises the parts of the
API a unit test would: parse_url splits path + params,
status_line/reason_phrase produce the documented strings, and
Response.json wires content-type correctly. The actual server
loop ([run]) requires Eio main, so it's documented in the prose
and not executed in the doc example.

+17 -6
+4
lib/dune
··· 2 2 (name respond) 3 3 (public_name respond) 4 4 (libraries eio logs magic-mime fmt nox-http)) 5 + 6 + (mdx 7 + (files respond.mli) 8 + (libraries respond))
+13 -6
lib/respond.mli
··· 3 3 {2 Quick Start} 4 4 5 5 {[ 6 - let open Respond in 7 - run ~net ~port:8080 ~root [ 8 - get "/api/health" (fun _params -> Response.json {|{"ok":true}|}); 9 - get "/api/cdms" (fun params -> ...); 10 - post "/api/login" (fun req -> ...); 11 - ] 6 + open Respond 7 + 8 + let path, params = parse_url "/api/items?page=2&sort=date" 9 + 10 + let () = 11 + assert (path = "/api/items"); 12 + assert (List.assoc "page" params = "2"); 13 + assert (List.assoc "sort" params = "date"); 14 + assert (status_line 404 = "404 Not Found"); 15 + assert (reason_phrase 200 = "OK"); 16 + let r = Response.json {|{"ok":true}|} in 17 + assert (r.status = 200); 18 + assert (r.content_type = "application/json") 12 19 ]} *) 13 20 14 21 open Http