package opium

  1. Overview
  2. Docs

Module Opium.AppSource

An opium app provides a set of convenience functions and types to construct a rock app.

  • Re-exporting common functions needed in handlers
  • Easy handling of routes and bodies
  • Automatic generation of a command line app
Sourcetype t

An opium app is a simple builder wrapper around a rock app

Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval empty : t

A basic empty app

Sourcetype builder = t -> t

A builder is a function that transforms an app by adding some functionality. Builders are usuallys composed with a base app using (|>) to create a full app

Sourceval sexp_of_builder : builder -> Sexplib0.Sexp.t
Sourceval port : int -> builder
Sourceval ssl : cert:string -> key:string -> builder
Sourceval cmd_name : string -> builder
Sourcetype route = string -> Opium_kernel.Rock.Handler.t -> builder

A route is a function that returns a buidler that hooks up a handler to a url mapping

Sourceval sexp_of_route : route -> Sexplib0.Sexp.t
Sourceval get : route

Method specific routes

Sourceval post : route
Sourceval delete : route
Sourceval put : route
Sourceval patch : route

Less common method specific routes

Sourceval options : route
Sourceval head : route
Sourceval any : Cohttp.Code.meth list -> route

any methods will bind a route to any http method inside of methods

all methods will bind a route to a URL regardless of the http method. You may escape the actual method used from the request passed.

Sourceval all : route

all methods will bind a route to a URL regardless of the http method. You may escape the actual method used from the request passed.

Sourceval action : Cohttp.Code.meth -> route

Convert an opium app to a rock app

Sourceval start : t -> unit Lwt.t

Start an opium server. The thread returned can be cancelled to shutdown the server

Sourceval run_command : t -> unit

Create a cmdliner command from an app and run lwt's event loop

Sourceval run_command' : t -> [> `Ok of unit Lwt.t | `Error | `Not_running ]
Sourcetype body = [
  1. | `Html of string
  2. | `Json of Ezjsonm.t
  3. | `Xml of string
  4. | `String of string
]

Convenience functions for a running opium app

Sourceval json_of_body_exn : Opium_kernel.Rock.Request.t -> Ezjsonm.t Lwt.t
Sourceval string_of_body_exn : Opium_kernel.Rock.Request.t -> string Lwt.t
Sourceval urlencoded_pairs_of_body : Opium_kernel.Rock.Request.t -> (string * string list) list Lwt.t
Sourceval param : Opium_kernel.Rock.Request.t -> string -> string
Sourceval splat : Opium_kernel.Rock.Request.t -> string list
Sourceval respond : ?headers:Cohttp.Header.t -> ?code:Cohttp.Code.status_code -> body -> Opium_kernel.Rock.Response.t
Sourceval respond' : ?headers:Cohttp.Header.t -> ?code:Cohttp.Code.status_code -> body -> Opium_kernel.Rock.Response.t Lwt.t
Sourceval redirect : ?headers:Cohttp.Header.t -> Uri.t -> Opium_kernel.Rock.Response.t
Sourceval redirect' : ?headers:Cohttp.Header.t -> Uri.t -> Opium_kernel.Rock.Response.t Lwt.t
OCaml

Innovation. Community. Security.