WSPath
Specifies a path to a REST Web service resource that identifies its function and allows parameters to be passed in the URL.
Syntax
WSPath = "/{
path-element |
value-template }
[
/...]
"
identifier
{identifier}
- path-element is a slash-separated list of path elements.
- value-template elements are place holders for a slash-separated list of variable values.
WSPath
is an optional attribute.
If there is no WSPath
specified, the function name (case sensitive) is the
path to the resource in the URI.
Usage
WSPath="/users"
The WSPath
string begins with a slash (/
), and there is a
slash between each path element and/or template value.
WSPath=/users/{id}
The path template is an identifier enclosed in curly brackets {}
. Zero, one, or
several path templates can be specified. Values are substituted when a GWS client makes a call to
the resource.
Path template values are provided at runtime in function parameters which have WSParam
attributes. As many template
values as path templates must be specified. In other words there must be a function parameter with a
WSParam
attribute to match each template path. fglcomp checks to
ensure that there is one template value per parameter, otherwise compilation error-9111 is thrown.
You set the WSPath
attribute in the ATTRIBUTES()
clause of the
function.
Example path templating with WSParam
In this sample REST function a user resource is returned. In the function's
p_user_id
parameter the attribute WSParam specifies the user to
return.
The WSPath
attribute sets the resource identifier or endpoint of the URI
to the resource. It contains the function's p_user_id
parameter enclosed in
curly brackets {}
as the path template.
The client application needs to provide an appropriate parameter value when making a call
to the function. For example, the variable part of the path (p_user_id
) is
replaced by the integer value /4
in the URL:
http://myhost:6394/gas/ws/r/myGroup/myXcf/MyService/accounts/4
TYPE accountType RECORD
user_id INTEGER,
user_name VARCHAR(50)
END RECORD
PUBLIC FUNCTION getAccountById(p_user_id INTEGER ATTRIBUTES(WSParam))
ATTRIBUTES(WSGet,
WSPath = "/accounts/{p_user_id}",
WSDescription = "Returns an account record",
WSThrows = "404:not found"
)
RETURNS accountType ATTRIBUTES(WSName = "Account",WSMedia = "application/json")
DEFINE p_accountRec accountType
SELECT * INTO p_accountRec.* FROM users WHERE id = p_user_id
RETURN p_accountRec
END FUNCTION