
http_parameters.pl -- Extract parameters (GET and POST) from HTTP requestsMost code doesn't need to use this directly; instead use library(http/http_server), which combines this library with the typical HTTP libraries that most servers need.
This module is used to extract the value of GET or POST parameters from an HTTP request. The typical usage is e.g.,
:- http_handler('/register_user', register_user, []).
register_user(Request) :-
http_parameters(Request,
[ name(Name, []),
sex(Sex, [oneof([male,female])]),
birth_year(BY, [between(1850,10000)])
]),
register_user(Name, Sex, BY),
html_reply_page(title('New user added'),
...).
http_parameters(+Request, ?Parms) is det
http_parameters(+Request, ?Parms, :Options) is detcall(Goal, A, Declarations).The attribute_declarations hook allows sharing the declaration of attribute-properties between many http_parameters/3 calls. In this form, the requested attribute takes only one argument and the options are acquired by calling the hook. For example:
...,
http_parameters(Request,
[ sex(Sex)
],
[ attribute_declarations(http_param)
]),
...
http_param(sex, [ oneof(male, female),
description('Sex of the person')
]).
http_convert_parameters(+Data, ?Params) is det
http_convert_parameters(+Data, ?Params, :AttrDecl) is det
http_parameters(Request, Params) :-
http_read_data(Request, Data, []),
http_convert_parameters(Data, Params).
http_convert_parameter(+Options, +FieldName, +ValueIn, -ValueOut) is detThe following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.
http_parameters(+Request, ?Parms) is det
http_parameters(+Request, ?Parms, :Options) is detcall(Goal, A, Declarations).The attribute_declarations hook allows sharing the declaration of attribute-properties between many http_parameters/3 calls. In this form, the requested attribute takes only one argument and the options are acquired by calling the hook. For example:
...,
http_parameters(Request,
[ sex(Sex)
],
[ attribute_declarations(http_param)
]),
...
http_param(sex, [ oneof(male, female),
description('Sex of the person')
]).
http_convert_parameters(+Data, ?Params) is det
http_convert_parameters(+Data, ?Params, :AttrDecl) is det
http_parameters(Request, Params) :-
http_read_data(Request, Data, []),
http_convert_parameters(Data, Params).