package vif
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=f2dafa4f12105d85b4dc2d1e1492f03e809c85d5834dc5694b99226418fe2719
sha512=1e2087db43e8e13bfc240c1114790ceb702b941d389bbb94a7a18668e65f61d2224f05038cf9101ede890581b0e2227e4d2bd2c620f312fa18c8e37482e273c4
doc/README.html
νιϝ, a small framework for building a web server from an OCaml script
(nu)(iota)(digamma)
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 server () =
let field = "content-type" in
let open Vif.Response.Syntax in
let* () = Vif.Response.add ~field "text/html; charset=utf-8" in
let* () = Vif.Response.with_string req "Hello World!" in
Vif.Response.respond `OK
;;
let routes =
let open Vif.Uri in
let open Vif.Route in
[ get (rel /?? nil) --> default ]
let () =
Miou_unix.run @@ fun () ->
Vif.run routes ()
;;
EOF
$ vif --pid vif.pid main.ml &
$ hurl http://localhost:8080/
HTTP/1.1 200 OK
connection: close
content-length: 12
content-type: text/html
Hello World!
$ kill -SIGINT $(cat vid.pid)Examples
The examples folder contains several examples of the use of vif. It shows the management of more complex requests (json, multipart-form, etc.) as well as the use of an SQL database with caqti. A complete example of a web application that uses dune is available here. It is a summary of our tutorial available here: creating a user space with a chatroom using Vif.