The main API let you define a HTTP daemon specification, which contains, among other parameters, a
callback function that is invoked each time a request is received. The callback function will
be invoked with an instance of an object representing the received HTTP request and an
connected to the remote HTTP client socket.
Then you can start your HTTP daemon invoking the
main function passing your specification. Each
time a client connect to the TCP port bound by your daemon, OCaml HTTP will parse the request and instantiate
the request object. If all goes well your callback will be invoked, otherwise appropriate error messages will
be sent back to the client without disturbing your callback.
You can use a lot of facility functions in your callback that permits you to send easily headers,
error responses, file, or abstract HTTP response objects. Otherwise you can also choose the 'hard way' and send
data directly to the
out_channel (expecially useful for sending data incrementally to the
client). You can also mix the two approaches.
Daemon specifications are used also to specify other parameters governing daemon behaviour like: TCP port and address to bind, way of handling incoming requests (handle all of them in a single process, fork a new process or spawn a new thread for each incoming request), timeout, authentication requirements (username and password for HTTP basic authentication).
OCaml HTTP contains also a tiny implementation of a HTTP client which can be used to retrieve resources via GET HTTP method and to iter on them (useful for huge resources which can't be kept in memory).
OCaml HTTP is freely distributed under the GNU Library General Public License (GPL) and is available here for download:
- tarball (sources) ocaml-http-0.1.5.tar.gz
- official Debian packages are available: libhttp-ocaml-dev
- browse the Git repository
If you're having trouble, and it looks like a bug in OCaml HTTP, please check to see if the bug is already reported, and if not, report it:
To build OCaml HTTP from sources you will need: