CoHTTP is an OCaml library for creating HTTP daemons. It has a portable HTTP parser, and implementations using various asynchronous programming libraries:
Cohttp_lwt_unixuses the Lwt library, and specifically the UNIX bindings.
Cohttp_asyncuses the Async library.
Cohttp_lwtexposes an OS-independent Lwt interface, which is used by the the Mirage interface to generate standalone microkernels (see the mirage-http repository).
You can implement other targets using the parser very easily. Look at the
lib/IO.mli signature and implement that in the desired backend.
You can activate some runtime debugging by setting
COHTTP_DEBUG to any
value, and all requests and responses will be written to stderr. Further
debugging of the connection layer can be obtained by setting
to any value.
Latest stable version should be obtained from opam. Make sure to install the specific backends you want as well. E.g.
$ opam install cohttp lwt js_of_ocaml
You can also obtain the development release:
$ opam pin add cohttp --dev-repo
Simple HTTP server
If you install the Async dependency, then a
cohttp-server-async binary will
also be built and installed that acts in a similar fashion to the Python
SimpleHTTPServer. Just run
cohttp-server-async in a directory and it will
open up a local port and serve the files over HTTP.
There is also an Lwt version of the SimpleHTTPServer installed as the
cohttp-server-lwt binary. The source code for both is in the
subdirectory and is a good starting point for how to write servers using