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
These manuals are available:
The examples directory of the repository has a few simple examples that use the APIs.
webs
webs.kit
Webs_gateway
Gateway interaction.Webs_hash
Hashing tools.Webs_authenticatable
Authenticatable data.Webs_authenticated_cookie
Authenticated cookies.Webs_session
Session handling.Webs_basic_auth
HTTP basic authentication.Webs_bazaar
Unstable service tools.webs.unix
Provides tools to send files and simple connectors. Depends on OCaml's unix
library.
Webs_unix
Webs Unix
tooling.Webs_thread_pool
Thread pools.Webs_listener
Socket connection listeners.Webs_fs
File system responses.Webs_cgi
CGI gateway connector.Webs_http11_gateway
HTTP/1.1 gateway connector.Webs_spawn_client
Client request by spawning.webs.cli
Standard command line options and quick service setup.
Webs_cli
Command line interface support.Webs_quick
Quick serves and fetches.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.
Before using Webs for your project you should be aware of these current limitations, some of which will be lifted in the future.
https
. You need to pair your service with an HTTP gateway like Apache, nginx, etc. See the HTTP service howto for more details. Alternatively you can develop your own connector with your own concurrency model.application/x-www-form-urlencoded
content type for form posting but it's missing an implementation of the multipart/form
body content type (e.g. to upload files). This will be added in the future so that Webs.Http.Request.to_query
eventually abstracts over all forms of queries.Webs_http11_gateway
connector will not fare well if you need to support WebSockets or SSE at scale.Webs_spawn_client
which is only ok for scripting or lightweight needs.Finally note that while Webs is unlikely to change drastically, making some breaking changes in the future is not excluded.