Library
Module
Module type
Parameter
Class
Class type
Path-based dispatching for client- and server-side applications.
Dispatch provides a basic mechanism for dispatching a request to a handler based on a conventionally heirarhical path name found in URIs. It can be used both for dispatching requests in a server, as well as handing changes to heirarchical fragments in a client-side application.
The type tag for a path component. `Lit
indiciates that the component should match exactly, while `Var
indicates that the component can be anything and should be associated with the variable name provided in the tuple.
The type of match for the route. `Prefix
indicates that the route does not need to match the entirety of the path, while `Exact
indicates an exact match.
The type of a route. The first tuple element specifies the matching rules for the path components, with the tag indicating the type of match. The corresponding string depends on the tag provided: for (`Lit, lit)
, the path component must match the string lit
exactly; for (`Var, name)
, the path component can be anything and will be associated with name
in the event of a successful match.
The second component of the tuple indicates the type of match that this route support, which can be either a prefix (`Prefix
) match, or an eact (`Exact
) match.
The third and final component is the value that will be returned in the event that the route matches the path.
val dispatch :
'a route list ->
string ->
('a * assoc * string option, string) Result.result
dispatch routes path
iterates through routes
and selects the first one that matches path
, returning with the route value any component mappings and trailing path components (in the case of a prefix match). If none of the routes
matches path
, it will return an Error
result.
dispatch_exn routes path
behaves just like dispatch routes path
except will raise an exception using failwith
in the case of no matches.
to_dsl route_spec
is a string in the routing DSL that will beahve in the exact same way as route_spec
.
A good way to become comfortable with the DSL is to load up this library in the REPL of your choice and translate route patterns to the DSL using the function to_dsl
.
module DSL : sig ... end
A module that implements the dispatch operations for a DLS represented as a string literal. A more familiar interface for the Web world.