Set resource path with WSParam and WSPath

Path parameters allow you to specify variables in the resource URL.

Path parameters are variable parts of a resource path. You would use them if you needed in your function to point to a specific resource within a collection, such as a user identified by ID, and when a pattern could match many similar resources. This is an example of the format of a resource path with path template.
/users/{id}

In the OpenAPI specification, the parts of the path that are replaceable with parameters are path templates. They are denoted with curly brackets {}. The path template is substituted with actual values when a GWS client makes a call to the resource.

For instance, if a client requests data for a specific user, the user id is provided in the URI http://host:port/gas/ws/r/MyService/users/22. A function in your web service with the path pattern above processes the request.

In GWS REST the WSPath and WSParam attributes support path templating. Path parameters are set in the attributes clause of the function with the WSPath attribute. For example:

ATTRIBUTES (WSGet,WSPath="/books/{bookId}/borrowers/{borrowerId}")
The input parameters with the WSParam attribute that must correspond to the templates in the path are described in Table 1. A call to the function with this path may return data for the specified borrower with a list of books borrowed.
Table 1. Path parameters
Parameter with WSParam attribute Description
bookId INTEGER ATTRIBUTE(WSParam)

A unique identifier for a book resource.

borrowerId INTEGER ATTRIBUTE(WSParam)

A unique identifier for a borrower resource.

Be aware that for each 4GL function input 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, otherwise compilation error-9111 is thrown.

Example path templating with WSPath and WSParam

PUBLIC FUNCTION sub(
    a INTEGER ATTRIBUTE(WSParam),
    b INTEGER ATTRIBUTE(WSParam) )
  ATTRIBUTES (WSGet,
              WSPath="/{a}/{b}/hello")
  RETURNS INTEGER
    RETURN a - b
END FUNCTION
The variable parts of the path are replaced by the values /4/8/ in this URL example:
http://host:port/gas/ws/r/MyService/4/8/hello