Page
Library
Module
Module type
Parameter
Class
Class type
Source
The current master branch is a WIP port to httpaf. If you are looking for the last version published to opam (that was using Cohttp), please take a look at https://github.com/rgrinberg/opium/tree/0.18.0
Sinatra like web toolkit for OCaml based on httpaf & lwt
Rock.The latest stable version is available on opam
$ opam install opium$ opam pin add rock.~dev https://github.com/rgrinberg/opium.git
$ opam pin add opium.~dev https://github.com/rgrinberg/opium.gitFor the API documentation:
odig: odig doc opium.The following tutorials walk through various usecases of Opium:
For examples of idiomatic usage, see the ./examples directory and the simple examples below.
Assuming the necessary dependencies are installed, $ dune build @example will compile all examples. The binaries are located in _build/default/example/.
You can execute these binaries directly, though in the examples below we use dune exec to run them.
Here's a simple hello world example to get your feet wet:
$ cat hello_world.ml
#include "example/hello_world/main.ml"compile and run with:
$ dune exec examples/hello_world.exe &then call
curl http://localhost:3000/person/john_doe/42 You should see the greeting
{"name":"john_doe","age":42}The two fundamental building blocks of opium are:
Request.t -> Response.t Lwt.tRock.Handler.t -> Rock.Handler.tAlmost all of opium's functionality is assembled through various middleware. For example: debugging, routing, serving static files, etc. Creating middleware is usually the most natural way to extend an opium app.
Here's how you'd create a simple middleware turning away everyone's favourite browser.
#include "example/simple_middleware/main.ml"Compile with:
$ dune build example/simple_middleware/main.mlHere we also use the ability of Opium to generate a cmdliner term to run your app. Run your executable with -h to see the options that are available to you. For example:
# run in debug mode on port 9000
$ dune exec dune build example/simple_middleware/main.exe -- -p 9000 -d