WSParam

Specifies a template as a path to a REST Web service resource.

Syntax

WSParam

Usage

You use this attribute for path templating to specify values that are provided at runtime in function parameters. You set the WSParam attribute in the ATTRIBUTES() clause of the function. This allows the GWS engine to identify a Web service resource by parameters passed in the URL at runtime.

WSParam is an optional attribute. Zero, one, or several parameters can be specified.

For each 4GL function parameter with a WSParam attribute, there must be a matching template value in the WSPath attribute value. fglcomp checks to ensure that there is one template value per parameter.

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
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 (id) is replaced by the integer value /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.

In the URL example the {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