Blob


1 The http module implements a http server. Functions (handlers) can be
2 associated to a specific route using [[handle]]. Routes are matched
3 per [[fnmatch::fnmatch]].
5 The http module relies on the event loop [[ev]].
7 Sample code:
9 use ev;
10 use fmt;
11 use http;
13 fn homepage(
14 req: *http::request,
15 res: *http::reswriter
16 ) (void | io::error) = {
17 http::reply(req, res, 200, "OK")?;
18 http::header(res, "Content-Type", "text/plain")?;
19 fmt::fprintln(res, "Hello, world!")?;
20 };
22 fn page2(...) // ...
24 export fn main() void = {
25 let sock = // ...
27 http::handle("/", &homepage);
28 http::handle("/2", &page2);
30 http::listen_sock(sock, null);
31 ev::mainloop()!;
32 };