Scroll to navigation

GOLF(2gg) Development GOLF(2gg)

NAME

get-param - (request-data)

PURPOSE

Get a parameter value.

SYNTAX

get-param ( <name> [ type <type> ] ) , ...

DESCRIPTION

get-param stores a parameter value in variable <name>. A parameter is a name/value pair kept by Golf for each request. The parameter's name must match <name>. A parameter can be of any type. A parameter is set either:

• by the caller in request URL, or

• with set-param statement anywhere during request's execution, including in call-handler.

If parameter is a string, it is trimmed for whitespaces (both on left and right). You can specify any number of parameters, separated by a comma.

TYPES

By default, <name> is a string variable, unless <type> (in "type" clause) is specified. <type> can be "string" for a string variable (the default), "bool" for a boolean variable, "number" for a number variable, "string-array" for an array of strings, "number-array" for an array of numbers, "bool-array" for an array of booleans, "message" for a message variable, "split-string" for a split-string variable, "hash" for an hash variable, "tree" for an tree variable, "tree-cursor" for an tree cursor variable, "fifo" for a FIFO variable, "lifo" for a LIFO variable, "list" for a list variable, "file" for a file variable, and "service" for a service variable.

The value obtained with get-param is checked to be of the proper <type>, and if it isn't, your request will error out. The exception to this is that a string parameter can be converted into a number or a boolean, assuming the string value represents a valid number or is "true"/"false". Parameters of "number" and "bool" types are obtained by value, and others by reference. It means for instance, that you can pass a tree to call-handler and read and write nodes there, and such changes will be visible in the caller request.

INPUT PARAMETERS FROM A CALLER

Input parameters in an external request (i.e. those parameters set by a caller outside of your application) are specified as name/value pairs (see service or command-line). Input parameter name can be made up of alphanumeric characters, hyphen or underscore only and cannot start with a digit. Note that a hyphen is automatically converted to underscore, so for instance an input parameter "some-parameter" in HTTP request will be "some_parameter" in get-param.

- File uploads

File uploads are handled as input parameters as well, see file-uploading.

- Web input parameters

As an example, for HTML form input parameters named "param1" with value "value1" and "param2" with value "value2":

<input type='hidden' name='param1' value='value1'>
<input type='hidden' name='param2' value='value2'>

you can get these parameters and print out their values by using:

get-param param1, param2

A request may be in the form of a web link URL, and getting the parameter values is the same:

http://<your web server>/<app name>/<request name>&param1=value1&param2=value2

SETTING PARAMETERS DURING REQUEST'S EXECUTION

Use set-param to replace the value of an existing parameter, or create a new one. For instance:

get-param par1
...
set-param par1="new value"

In this case the value of an existing parameter "par1" is replaced with "new value". In the following code a new parameter is created, which can be retrieved later with get-param:

set-param par1="new value"
get-param par1

See call-handler for more examples.

DUPLICATE INPUT PARAMETER NAMES

If there are multiple input parameters with the same name set by the request caller, such as

http://<web address>/<app name>/<request name>?par=val1&par=val2

the value of input parameter "par" is undefined. Do not specify multiple input parameters with the same name.

SEE ALSO


Request data

get-param request-body set-param See all documentation

$VERSION $DATE