Set query, header, or cookie parameters (if needed)
You define these parameters in your function if the resource needs data to be passed as query, cookie, or header.
The GWS REST engine provides support for the OpenAPI specification requirements for the
following standard parameters:
- Query parameters. These are set at the end of the resource URL after a question mark
(
?
), with differentname=value
pairs separated by ampersands (&
). Query parameters can be required and optional. - Header parameters, such as
X-MyHeader:Value
. These are custom headers to be sent with an HTTP request or response. - Cookie parameters, are passed in the
Cookie
header. For example,Cookie:ctoken=BUSe35dohU4O1MZxDCU
.
Parameter attributes
You use the following attributes if there is requirement for them in your Web service
function.
- 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/findbycountry?country=france
. - WSHeader. Header attributes may be
specified in an input parameter or in a return value of your function. The
Content-Type:text/html
header, for example, indicates the media type of the response sent to the client by the server. This helps the client in processing the response body correctly. Custom headers are commonly used for informational purposes, but you can also use them for passing data to implement logic on the server or client side. - WSCookie. The cookie attribute is dedicated to the need for cookies in your function.
You can set these parameters as optional with the WSOptional attribute as shown for the cookie in the sample function.
Example use of parameter attributes
PUBLIC FUNCTION add(
a INTEGER ATTRIBUTE(WSQuery),
b INTEGER ATTRIBUTE(WSHeader),
coef FLOAT ATTRIBUTE(WSCookie,WSOptional) )
ATTRIBUTES (WSGet,
WSPath="/add")
RETURNS INTEGER
RETURN a + b
END FUNCTION
Your
client application must set the custom header and cookie parameter (optional) values in a call to
the function. The
WSQuery
parameter forms the query string of the resource path,
?a=3
in this example of the resource
URL:http://host:port/gas/ws/r/MyService/add?a=3