Module Restful.Param

module Param: sig .. end

Functions to process QUERY_STRING parameters. These functions handle mandatory vs. optional parameters, validation, and unexpected parameters.


type mandopt = 
| Mandatory
| Optional

Types of QUERY_STRING parameters

type spec = string * mandopt * (string -> bool) 

The type of parameter specifications.

type specs = spec list 

The type of parameter specification lists.

type vparms 

The type of validated parameter lists.

val process : ?strict:bool -> Netcgi.cgi -> specs -> vparms

process ?strict cgi spec: process QUERY_STRING parameters according to spec, returning validated parameter list.

strict : if true, it is a 400 error to provide parameters not mentioned in spec (default: false)
val value : ?default:string -> vparms -> string -> string

value ?default params name: given a validated parameter list params, as returned by process, and a parameter name, return the value of the parameter. If value is called for an Optional parameter that was not provided, a 500 error will be raised unless the ?default parameter was provided.

default : default value for an Optional parameter
val optvalue : vparms -> string -> string option

optvalue params name: given a validated parameter list params, as returned by process, and a parameter name, return the value of the parameter as a string option. Works for both Optional and Mandatory parameters.

val get : Netcgi.cgi ->
mandopt -> (string -> bool) -> string -> string option

get cgi mandopt validator name: get one QUERY_STRING parameter name, validating it with validator. If mandopt is Mandatory and the parameter is not provided, a User_exn is raised. If validator returns false, a User_exn is raised.

The return value is a string option; if mandopt is Mandatory, a Some is guaranteed (else an error will have been raised).

val at_least_one : string list -> vparms -> vparms

at_least_one names vp: insist that at least one of the parameters in names is given.

Use this when at least one of several parameters, which are all themselves optional, are required.

val mutex : ?atleast:bool ->
string list -> string list -> vparms -> vparms

mutex ?atleast x y vp: reject mutually exclusive parameters.

x and y are interpreted as two sets of mutually exclusive parameter names.

atleast : if true, then at least one of the x's or y's must be given