package opium
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=483f6c60c5e31c2b9fc836a9da14a8693a38b725aa164732bdb2be71fe5754d5
sha512=b19588173126bc8bd5823f1a6e94a1c3c2ce1abcf1defb3ff8ce0a613e22492160feaeb4e22d01044cac409077b863d1ebd1445e103f6602f45e56f51bb567a0
doc/index.html
Opium
Welcome to Opium's documentation!
Overview
Opium is a web framework for OCaml.
Installation
In order to build an Opium app, you will need to install a few dependencies on your system. You can use either Esy to Opam for this.
Install with Opam
To install Opium with opam, you can run opam install opium. You can then run opam info opium to make sure the library has been installed correctly.
Install with Esy
To install Opium with esy, you can run esy add @opam/opium, this will add an entry "@opam/opium": "*" to your package.json and install the dependency. You can then run esy ls-modules to make sure the library has been installed correctly.
Use in a Dune project
To use Opium in your dune project, you can add opium to the libraries stanza in your dune file.
If you are building a library, this will look like this:
(library
(public_name mylib)
(libraries opium))And for an executable:
(executable
(public_name myexe)
(libraries opium))That's it, you can now start using Opium!
Getting Started
Here is an example of a simple Opium application:
open Opium
let hello _req = Response.of_plain_text "Hello World" |> Lwt.return
let greet req =
let name = Router.param req "name" in
Printf.sprintf "Hello, %s" name |> Response.of_plain_text |> Lwt.return
let () =
let open App in
App.empty
|> App.get "/" hello
|> App.get "/greet/:name" greet
|> App.run_command
|> ignoreWhen run, the executable will start an HTTP server with two endpoints:
/will return atext/plainresponse with the content"Hello World"/greet/:namewill return atext/plainresponse with a greeting of the name passed in the URL