package sihl

  1. Overview
  2. Docs
type meth =
  1. | Get
  2. | Head
  3. | Options
  4. | Post
  5. | Put
  6. | Patch
  7. | Delete
  8. | Any

HTTP method

A handler returns a response given a request.

type route = meth * string * handler

A route has an HTTP method, a path and a handler.

type router = {
  1. scope : string;
  2. routes : route list;
  3. middlewares : Rock.Middleware.t list;
}

A router has a scope, a list of routes and a list of middlewares. A mounted router prefixes all routes and applies the middlewares to them.

val get : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

get path ?middlewares handler returns a router with a single GET route containing the handler. The scope of the router is path.

val head : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

head path ?middlewares handler returns a router with a single HEAD route containing the handler. The scope of the router is path.

val options : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

options path ?middlewares handler returns a router with a single OPTIONS route containing the handler. The scope of the router is path.

val post : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

post path ?middlewares handler returns a router with a single POST route containing the handler. The scope of the router is path.

val put : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

put path ?middlewares handler returns a router with a single PUT route containing the handler. The scope of the router is path.

val patch : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

patch path ?middlewares handler returns a router with a single PATCH route containing the handler. The scope of the router is path.

val delete : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

delete path ?middlewares handler returns a router with a single DELETE route containing the handler. The scope of the router is path.

val any : string -> ?middlewares:Rock.Middleware.t list -> handler -> router

any path ?middlewares handler returns a router with a single route containing the handler. The scope of the router is path. This route matches any HTTP method.

val routes_of_router : router -> route list

routes_of_router router applies the middlewares, routes and the scope of a router and returns a list of routes.

val choose : ?scope:string -> ?middlewares:Rock.Middleware.t list -> router list -> router

choose ?scope ?middlewares routers returns a router by combining a list of routers.

scope is the new scope under which all routers are mounted.

middlewares is an optional list of middlewares that are applied for all routers. By default, this list is empty.

routers is the list of routers to combine.

val externalize_path : ?prefix:string -> string -> string

externalize_path ?prefix path returns a path with a prefix added.

If no prefix is provided, PREFIX_PATH is used. If PREFIX_PATH is not provided, the returned path equals the provided path.

module Request : sig ... end
module Response = Opium.Response
module Body = Opium.Body
module Router = Opium.Router
module Route = Opium.Route
module Http : sig ... end
module Csrf : sig ... end
module Flash : sig ... end
module Rest : sig ... end

This module allows you to build RESTful web pages quickly.

module Htmx : sig ... end

This module simplifies dealing with HTMX requests by adding type safe helpers to manipulate HTMX headers. Visit https://htmx.org/reference/ for the HTMX documentation.

module Id : sig ... end
module Session : sig ... end
module Middleware : sig ... end
OCaml

Innovation. Community. Security.