webmachine

A REST toolkit for OCaml
IN THIS PACKAGE
Module Webmachine . Rd
type 'body t = {
version : Cohttp.Code.version;
meth : Cohttp.Code.meth;
uri : Uri.t;
req_headers : Cohttp.Header.t;
req_body : 'body;
resp_headers : Cohttp.Header.t;
resp_body : 'body;
resp_redirect : bool;
dispatch_path : string;
path_info : (string * string) list;
} constraint 'body = [> `Empty ]
val make : ?dispatch_path:string -> ?path_info:(string * string) list -> ?resp_headers:Cohttp.Header.t -> ?resp_body:'a -> ?resp_redirect:bool -> ?req_body:'a -> request:Cohttp.Request.t -> unit -> 'a t

make ~request () returns a 'body t with the following fields pouplated from the request argument:

  • uri
  • version
  • meth
  • req_headers

.

All other fields will be populated with default values unless they are provided as optional arguments

val with_req_headers : ( Cohttp.Header.t -> Cohttp.Header.t ) -> 'a t -> 'a t

with_req_headers f t is equivalent to { t with req_headers = f (t.req_headers) }

val with_resp_headers : ( Cohttp.Header.t -> Cohttp.Header.t ) -> 'a t -> 'a t

with_resp_headers f t is equivalent to { t with resp_headers = f (t.resp_headers) }

val lookup_path_info : string -> 'a t -> string option
val lookup_path_info_exn : string -> 'a t -> string

lookup_path_info_exn k t is equivalent List.assoc k t.path_info, which will throw a Not_found exception if the lookup fails. The non-_exn version will return an optional result.

val redirect : string -> 'a t -> 'a t

redirect location t sets the resp_redirect bit in t and sets the Location response header to location.