Module Simple_httpd.RouteSource

Module defining Routes to select which function will answer a request

Routing

Basic type-safe routing.

Sourcetype ('a, 'b) comp
Sourcetype ('a, 'b) t

A route, composed of path components

Sourceval int : (int -> 'a, 'a) comp

Matches an integer.

Sourceval string : (string -> 'a, 'a) comp

Matches a string not containing '/' and binds it as is.

Sourceval exact : string -> ('a, 'a) comp

exact "s" matches "s" and nothing else.

Sourceval return : ('a, 'a) t

Matches the empty path.

Sourceval rest : (string list -> 'a, 'a) t

Matches a string, even containing '/'. This will match the entirety of the remaining route.

Sourceval (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t

comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".

Sourceval exact_path : string -> ('a, 'b) t -> ('a, 'b) t

exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r *

Sourceval pp : Format.formatter -> (_, _) t -> unit

Print the route. 0.7

Sourceval to_string : (_, _) t -> string

Print the route. 0.7

Sourceval pass : unit -> 'a

This function may be called in a handler to try the next request. It must be raised after reading only the path, not the request. Your handler should look like: fun path -> if bad path then pass (); fun req -> ...