Instantiate a Router module with custom default values.
Example using Cohttp_async:
open Cohttp_async
module Custom_config = struct
let default_exn_handler ?vars:_ exn =
let status, body =
match exn with
| Exceptions.Bad_request msg -> `Bad_request, Body.empty
| _ -> `Internal_server_error,
Body.of_string "An unexpected error occurred" in
Io.return (Response.make ~status (), body)
let default_fallback ?vars:_ _req _body =
Io.return (Response.make ~status:`Not_found (), Body.empty)
end
module Router = Make (Request) (Body) (Response) (Io) (Custom_config)include Ocamlapi__.S.Router_typesA 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".
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