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.
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")]
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
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.
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.