Webs v0.0.0-148-g65ff953

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

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

Manuals

These manuals are available:

The test 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

See also the samples in the dev repo.

Fetch

Fetch an URL with this fetch.ml file:

open Webs
open Result.Syntax

let main () =
  Result.retract @@ Result.map_error (fun e -> prerr_endline e; 1) @@
  let url = Sys.argv.(1) in
  let* httpc = Webs_spawn_client.make () in
  let* page = Http_client.get httpc ~follow:true ~url in
  print_endline page;
  Ok 0

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

Compile and run with:

ocamlfind ocamlopt -linkpkg -package webs,webs.unix -o fetch fetch.ml
./fetch https://example.org   # needs curl in your PATH

Serve

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 and run with:

ocamlfind ocamlopt -linkpkg -package webs,webs.unix,webs.cli -o serve serve.ml
./serve &
curl http://localhost:8000/hey
./fetch http://localhost:8000/hey
pkill serve
./serve --help

Limitations

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