Set query, header, or cookie parameters
Define the WSQuery, WSHeader, or
WSCookie parameters in your function if the resource needs data passed as a query,
cookie, or header.
- Query parameters. Set query parameters after a question mark (
?) at the end of the resource URL. Ampersands (&) separate differentname=valuepairs. Query parameters can be required or optional. - Header parameters, such as
X-MyHeader:Value. These are custom headers sent with an HTTP request or response. - Cookie parameters. The
Cookieheader passes these parameters, for exampleCookie:ctoken=BUSe35dohU4O1MZxDCU.
Parameter attributes
- WSQuery.
You can specify this attribute only in an input parameter of your function. Its use is suited to filtering on resource collections, such as
/users?country=france. If in doubt about whether to useWSParamorWSQuery, see When to use WSParam or WSQuery. - WSHeader.
Use this attribute to specify an input parameter to your function as a custom header, or a return value from your function as a custom header. Use custom headers to pass data to implement logic on the server or client side.
- WSCookie.
Use this attribute to specify an input parameter in your function that contains a cookie.
You can set these parameters as optional with the WSOptional attribute.
Example use of parameter attributes
TYPE profileType RECORD ... END RECORD
PUBLIC FUNCTION getUsersStatus(
stat STRING ATTRIBUTE(WSQuery, WSOptional, WSName="status"),
sort_field STRING ATTRIBUTE(WSHeader, WSOptional, WSName="sortby"),
country STRING ATTRIBUTE(WSCookie, WSOptional, WSName = "ccode" )
)
ATTRIBUTES (WSGet,
WSPath = "/users",
WSDescription = "Gets users with the optional query, sort, and cookie values applied.")
RETURNS ( DYNAMIC ARRAY ATTRIBUTE(WSName="Users_status",
WSMedia="application/json") OF profileType ATTRIBUTE(XMLName="User"))
DEFINE userStatusList DYNAMIC ARRAY OF profileType
# ... function code ...
RETURN userStatusList
END FUNCTIONIn
this example,-
When the client application calls this function, providing values for the custom header, the cookie, or the query is optional because of the
WSOptionalattribute. -
If specified, the
WSQueryparameter forms the query string of the resource path. In this example, "?status=active" is the query string:http://host:port/gas/ws/r/group/xcf/Accounts/users?status=active -
The XML output is customized by
WSNameandXMLNameattributes.