sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Instantiate a Router module.
Example using Cohttp_async
:
open Cohttp_async
module Router = Make (Request) (Body) (Response) (Io)
module Req : Cohttp.S.Request
module Body : sig ... end
module Resp : Cohttp.S.Response
module IO : sig ... end
A 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"
.
type exn_handler =
?vars:string Core.String.Table.t ->
exn ->
(Resp.t * Body.t) IO.t
A function of this type is called whenever a callback throws an exception.
type route = string * (Cohttp.Code.meth * callback) list
Represents a url path with a list of supported http methods.
module type Routes = sig ... end
If 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_handler
If no exception handler is given while creating a router, default_exn_handler
gets used.
val default_fallback : callback
If 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.t
Create a router
val create_exn :
?exn_handler:exn_handler ->
?fallback_response:callback ->
route list ->
t
val create_from_modules :
?exn_handler:exn_handler ->
?fallback_response:callback ->
(module Routes) list ->
(t, exn) Core.Result.t
A 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