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.
Usage
You use this attribute to define the format of the URL of the REST resource. You set the
WSPath
attribute in the ATTRIBUTES()
clause of the function. It
allows you to identify a Web service resource with a path or by providing for parameters to be
passed in the URL at runtime.
The value-template option supports path templating for values that are
provided at runtime in function parameters with WSParam
attributes. Zero, one, or
several template values can be specified. There must be a 4GL function parameter with a
WSParam
attribute that
matches each template value. fglcomp checks to ensure that there is one parameter
per template value.
WSPath
string begins with a slash (/
), and there is a
slash between each path element and/or template value. WSPath
is an optional attribute. If there is no WSPath
specified, the function name (case sensitive) is the path to the resource in the URL.
Example 1 path templating with WSParam
TYPE accountType RECORD
id INT,
name VARCHAR(50),
email VARCHAR(100)
END RECORD
PUBLIC FUNCTION getAccountById(id ATTRIBUTE(WSParam) )
ATTRIBUTES(WSGet,
WSPath="/accounts/{id}",
WSDescription="Returns an account record",
WSThrows="404:not found"
)
RETURNS accountType
DEFINE p_accountRec accountType)
# ... function code ...
RETURN p_accountRec
END FUNCTION
/4
in the
URL:http://host:port/gas/ws/r/MyService/accounts/4
Example 2 path templating and query string
PUBLIC FUNCTION add(
a INTEGER ATTRIBUTE(WSQuery),
b INTEGER ATTRIBUTE(WSQuery),
coef FLOAT ATTRIBUTE(WSParam) )
ATTRIBUTES (WSGet,
WSPath='/add/{coef}')
RETURNS FLOAT
RETURN (a + b) * coef
END FUNCTION
The WSParam
parameter represents an identifier in the path of your URL, while
the WSQuery
parameters
represent its query string.
{coef}
path parameter is replaced with the value "2" in
the URL. This function also has two WSQuery
parameters, which form the query string
of the URL
?a=3&b=8
:http://host:port/gas/ws/r/MyService/add/2?a=3&b=8