Webs is a toolkit for programming with HTTP in OCaml. It provides:
Webs is not a framework, it is a set of building blocks.
These manuals are available:
The test directory of the repository has a few simple examples that use the APIs.
websWebs HTTP interactions. Open to use it.Webs.Http HTTP datatypes.Webs.Http.Request HTTP requests.Webs.Http.Response HTTP responses.Webs.Http_client HTTP clients.Webs.Media_type Media type constants and file extensions.Webs.Url Sloppy URL processing.webs.kitWebs_authenticatable Authenticatable data.Webs_authenticated_cookie Authenticated cookies.Webs_base64 base64 and base64url codecs.Webs_basic_auth HTTP basic authentication.Webs_bazaar Unstable service tools.Webs_cryptorand Cryptographically secure pseudorandom bytes and entropy.Webs_gateway Gateway interaction.Webs_hash Hashing tools.Webs_session Session handling.webs.unixProvides 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.cliStandard command line options and quick service setup.
Webs_cli Command line interface support.Webs_quick Quick serves and fetches.See also the samples in the dev repo.
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 PATHMake 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 --helpBefore 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 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.