package wtr

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

URI

type ('a, 'b) uri

('a, 'b) uri represents a URI - both the path and query, e.g. /home/about/, /home/contact, /home/contact?name=a&no=123 etc.

A uri is created via usage of wtr.ppx.

val pp_uri : Format.formatter -> ('a, 'b) uri -> unit

pp_uri fmt uri pretty prints uri on to fmt.

Route

type 'c route

'c route is a uri and its handler. 'c represents the value returned by the handler.

val (>-) : ('a, 'b) uri -> 'a -> 'b route

p >- route_handler creates a route from uri p and route_handler.

Router

type 'a t

'a t represents a Trie based router.

val create : 'a route list -> 'a t

create routes creates a router from a list of routes.

val match' : 'a t -> string -> 'a option

match t uri matches a route to uri, executes its handler and returns the computed value. None is returned if uri is not matched.

URI Decoder

type 'a decoder

Represents a uri component decoder, such as :int, :float, :bool etc.

module type Decoder = sig ... end

All user defined decoders conform to the module signature decoder.

val create_decoder : name:string -> decode:(string -> 'a option) -> 'a decoder

create_decoder ~name ~decode creates a user defined decoder uri component. name is used during the pretty printing of uri.

OCaml

Innovation. Community. Security.