No description
Find a file
2025-02-09 18:56:08 +01:00
bin Add caqti example 2025-02-02 13:29:07 +01:00
examples Better support for deflate 2025-02-09 13:56:39 +01:00
lib Add middleware 2025-02-09 18:56:08 +01:00
.ocamlformat First commit 2024-12-30 13:41:55 +01:00
.ocamlformat-ignore Add caqti example 2025-02-02 13:29:07 +01:00
dune-project First commit 2024-12-30 13:41:55 +01:00
README.md Add a README.md 2025-02-02 15:00:21 +01:00
TODO.md Add caqti example 2025-02-02 13:29:07 +01:00
vif.opam Opam dependencies (#1) 2025-01-22 10:54:30 +00:00

Vif, a small framework for building a web server from an OCaml script

disclaimer: Please note that this is an experimental project. It's also an opportunity to build something that can be satisfying for web development. However, we do not recommend using this project in production.

Vif is a small program that runs an OCaml script and launches a Web server from it. The main idea is to be able to set up a typed Web server as quickly as possible (note that we use hurl, an HTTP client in OCaml)

$ opam pin add -y https://github.com/robur-coop/vif
$ opam pin add -y https://github.com/robur-coop/hurl
$ opam install vif hurl
$ cat >main.ml <<EOF
#require "vif" ;;

let default req target server () =
  let headers = [ "content-type", "text/html" ] in
  Vif.Response.with_string ~headers server `OK "Hello World!\n"
;;

let () =
  Miou_unix.run @@ fun () ->
  Vif.run ~default [] ()
;;
EOF
$ vif --pid vif.pid main.ml &
$ hurl http://localhost:8080/
HTTP/1.1 200 OK

connection: close
content-length: 13
content-type: text/html

Hello World!

$ kill -SIGINT $(cat vid.pid)