Page
Library
Module
Module type
Parameter
Class
Class type
Source
Ocamlapi.MakeInstantiate a Router module.
Example using Cohttp_async:
open Cohttp_async
module Router = Make (Request) (Body) (Response) (Io)module Req : Cohttp.S.Requestmodule Body : sig ... endmodule Resp : Cohttp.S.Responsemodule IO : sig ... endA function of this type is called whenever a request matches a route. The vars argument is a table where the keys are the variable names declared in dynamic path segments, and the values are their values as appearing in the route that this request matched against.
For example, if a request made to the path "/user/david" matches against a route "/user/<name>", then the corresponding callback will be given a vars with a single key "name", and the associated value will be "david".
A function of this type is called whenever a callback throws an exception.
type route = string * (Cohttp.Code.meth * callback) listRepresents a url path with a list of supported http methods.
module type Routes = sig ... endIf a module declares a list of routes named routes, it can be passed as a first-class value to the create_from_modules functions below.
val default_exn_handler : exn_handlerIf no exception handler is given while creating a router, default_exn_handler gets used.
val default_fallback : callbackIf no fallback callback is given while creating a router, default_fallback gets used.
val create :
?exn_handler:exn_handler ->
?fallback_response:callback ->
route list ->
(t, exn) Core.Result.tCreate a router
val create_exn :
?exn_handler:exn_handler ->
?fallback_response:callback ->
route list ->
tval create_from_modules :
?exn_handler:exn_handler ->
?fallback_response:callback ->
(module Routes) list ->
(t, exn) Core.Result.tA convenience function to create a router from a list of modules, each of which declare a routes function.
val create_from_modules_exn :
?exn_handler:exn_handler ->
?fallback_response:callback ->
(module Routes) list ->
t