package routes

  1. Overview
  2. Docs
Typed routing for OCaml applications

Install

Dune Dependency

Authors

Maintainers

Sources

routes-0.5.0.tbz
sha256=d209a537921c30769b8c1875d473357a88918a3289ba00bcb77d4442990ade73
sha512=3ebade912f1589c97ee88c1b1a7c8e3c38b2ac41e4e3805b34e0843460ed14779f5e584ae885638976a6d4b4d5849ccb41c6712b238990a9f358ed669971e839

doc/routes/Routes/index.html

Module RoutesSource

Typed routing for OCaml. Routes provides combinators for adding typed routing to OCaml applications. The core library will be independent of any particular web framework or runtime.

Sourcemodule Method : sig ... end
Sourcetype 'a t

'a t represents a path parameter of type 'a.

Sourcetype 'a router

'a router represents the internal router data type, where each route can potentially return a value of type 'a .

Sourceval return : 'a -> 'a t

return v is a path param parser that always returns v.

Sourceval apply : ('a -> 'b) t -> 'a t -> 'b t

apply f t applies a function f that is wrapped inside a 'a t context to a path param parser. f <*> p is the same as f >>= fun f -> map ~f p

Sourceval s : string -> unit t

s word returns a path parser that matches word exactly and then discards the result.

Sourceval int : int t

int parses a path parmeter and succeeds if its an integer.

Sourceval int32 : int32 t

int32 parses a path parameter and succeeds if its a valid 32 bit integer.

Sourceval int64 : int64 t

int64 parses a path parameter and succeeds if its a valid 64 bit integer.

Sourceval bool : bool t

bool parses a path parameter and succeeds if its either "true" or "false".

Sourceval str : string t

str parses a path param and returns it as a string.

Sourceval empty : unit t

empty matches an empty target. This can be used to match against "/".

Sourceval one_of : 'a t list -> 'a router

one_of accepts a list of route parsers and converts into a router.

Sourceval with_method : (Method.t * 'a t) list -> 'a router

with_method accepts a list of routes + http methods and converts it into a router. This will also group methods based on the Http verb. If there are multiple route definitions that overlap and are potential matches, the one defined first will be returned.

Sourceval match' : 'a router -> string -> 'a option

match' runs the router against the provided target url.

Sourceval match_with_method : 'a router -> target:string -> meth:Method.t -> 'a option

match_with_method is used to run the router. It accepts a target url string, HTTP method verb a request of any type (which is forwarded as the last parameter to the handler functions). If a route matches it runs the attached handler and returns the result.

Sourcemodule Infix : sig ... end
Sourcemodule Routes_private : sig ... end
OCaml

Innovation. Community. Security.