WSQuery

Specifies the query string that appears after a question mark (?) in the request URL.

Syntax

WSQuery

This attribute supports a query in the URL. Zero, one, or several parameters can be specified.

WSQuery is an optional attribute.

Usage

You set the WSQuery attribute in an ATTRIBUTE() clause of an input parameter (only) of the function. Its use is suited to filtering on resource collections. The client application needs to provide appropriate parameter values in the URL when making a call to the function, such as /users?fname=john.

Example WSQuery

TYPE accountType RECORD
       id VARCHAR(10),
       fname VARCHAR(25),
       lname VARCHAR(25)
       # ...
    END RECORD
    
PUBLIC FUNCTION getAccountRecords(
    resourceId VARCHAR(10) ATTRIBUTES(WSQuery, WSOptional, WSName = "id"),
    firstName VARCHAR(25) ATTRIBUTES(WSQuery, WSOptional, WSName = "fname"),
    lastName VARCHAR(25) ATTRIBUTES(WSQuery, WSOptional, WSName = "lname"))
  ATTRIBUTES (WSGet, 
              WSPath = "/accounts",
              WSDescription = "Fetches the accounts resource with the optional filter value(s) applied.",
        WSScope = "officestore.user",
        WSThrows = "404:Not Found,500:Internal Server Error")
  RETURNS (DYNAMIC ARRAY ATTRIBUTE(WSName = "accounts") OF
        accountType ATTRIBUTES(XMLName = "account", WSMedia = "application/json, application/xml"))
  
    DEFINE recList DYNAMIC ARRAY OF accountType
 
   # ... function code ...
   
    RETURN recList
END FUNCTION
This function has WSQuery parameters which are optional. This allows the function to be used to query any of the parameter values if provided in the query string of the URL, for example:
http://host:port/gas/ws/r/MyService/accounts?fname=value&lname=value
or
http://host:port/gas/ws/r/MyService/accounts?lname=value