Get param

Purpose: Get a parameter value.

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

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:
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, "double" for a double variable, "string-array" for an array of strings, "number-array" for an array of numbers, "double-array" for an array of doubles, "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, double or a boolean, assuming the string value represents a valid number, double or is "true"/"false"; this exception is for request URL parameters only.  Parameters of "number", "double" 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.
Default value
If "default-value" clause is used, then <value> will be assigned to <name> variable if there is none provided. For example, if the caller does not specify the value for parameter <name>, then its value will be <value>; note that parameter must always have value so if none is provided and there is no default value specified, your program will error out. "default-value" can only be used with strings, numbers, doubles and booleans.
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


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.