Tree


READMEcommits | blame
buf.hacommits | blame
http.hacommits | blame
listen.hacommits | blame
mux.hacommits | blame
reswriter.hacommits | blame

README

The http module implements a http server.  Functions (handlers) can be
associated to a specific route using [[handle]].  Routes are matched
per [[fnmatch::fnmatch]].

The http module relies on the event loop [[ev]].

Sample code:

	use ev;
	use fmt;
	use http;

	fn homepage(
		req: *http::request,
		res: *http::reswriter
	) (void | io::error) = {
		http::reply(req, res, 200, "OK")?;
		http::header(res, "Content-Type", "text/plain")?;
		fmt::fprintln(res, "Hello, world!")?;
	};

	fn page2(...) // ...

	export fn main() void = {
		let sock = // ...

		http::handle("/", &homepage);
		http::handle("/2", &page2);

		http::listen_sock(sock, null);
		ev::mainloop()!;
	};