Webs v0.0.0-118-g08c902b

Webs is a toolkit for programming with HTTP in OCaml. It provides:

Webs is not a framework, it is a set of building blocks.

See the quick start and the limitations

Manuals

These manuals are available:

The examples directory of the repository has a few simple examples that use the APIs.

Library webs

Library webs.kit

Library webs.unix

Provides tools to send files and simple connectors. Depends on OCaml's unix library.

Service connectors

Client connectors

Library webs.cli

Standard command line options and quick service setup.

Quick start

Fetch an URL with this fetch.ml file:

open Webs

let main () =
  let httpc = Webs_spawn_client.make () in
  let url = Sys.argv.(1) in
  match Http_client.get httpc ~follow:true ~url with
  | Error e -> prerr_endline e; 1
  | Ok page -> print_endline page; 0

let () = if !Sys.interactive then () else exit (main ())

Make a minimal server with this serve.ml file:

open Webs

let service = Http.Request.echo
let main () = Webs_quick.serve service
let () = if !Sys.interactive then () else exit (main ())

Compile that with

ocamlfind ocamlopt -pkg webs,webs.unix -o fetch fetch.ml
ocamlfind ocamlopt -pkg webs,webs.http11,webs.cli -o serve serve.ml

Let them talk (you will need curl in your PATH):

./serve &
./fetch http://localhost:8000/hey
./fetch http://localhost:8000/ho
pkill serve
serve --help

See also the samples in the repo.

Limitations

Before using Webs for your project you should be aware of these current limitations, some of which will be lifted in the future.

Finally note that while Webs is unlikely to change drastically, making some breaking changes in the future is not excluded.