Module ReWeb.Form

Encode and decode web forms to/from specified types.

Use make (see below) to create a www form that can be decoded to custom types using the form validation rules defined in fields. Use encode to encode a value as a form.

type 'a decoder = string -> ('a, string) Stdlib.result

A decoder is a function that takes an encoded value and returns a result of decoding the value.

module Field : sig ... end

Allows creating a list of form fields using normal list syntax with a local open (e.g. Field.[bool("remember-me"), string("username")]

type ('ctor, 'ty) t

A web form is a list of fields and a 'constructor' that takes their decoded field values and returns a value of type 'ty.

val decode : ('ctor'ty) t -> (string * string list) list -> ('ty, string) Stdlib.result
val decoder : ('ctor'ty) t -> 'ty decoder

decoder(form) takes a form definition (see above) and returns a decoder from that form to a type 'ty.

val empty : (unit, unit) t

empty is an empty form i.e. one that does not decode any form data and always succeeds at it.

val encode : ('ty -> (string * string) list) -> 'ty -> string

encode(fields, value) is a query-encoded string form. It calls fields value to get the representation of value as a list of key-value string pairs.

val make : ('ctor'ty) Field.list -> 'ctor -> ('ctor'ty) t

make(fields, ctor) allows creating a form that can be used to decode (with decoder) www forms.