package opium
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=326b91866de90baf535f8b7d4b2ff23e39d952e573c04b3c13f1054b59ff2fb6
sha512=59b83e7c8fe5f7ae328fb7f2343fe5b8fb735e8f6ee263cfd6c75bb179688ef7cf2b4586b35a2231ed3f3c1ada543021b7a4759326ae095eb77a5f38b9fa3a8a
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