WSPath

Specifies a path to a REST Web service resource that identifies its function and allows parameters to be passed in the URL.

Syntax

WSPath = "/{ path-element | value-template } [/...]"
where path-element is an identifier:
identifier
and where value-template is an identifier enclosed in curly brackets:
{identifier}
  1. path-element is a slash-separated list of path elements
  2. value-template elements are place holders for a slash-separated list of variable values.

WSPath is an optional attribute.

Note: If there is no WSPath specified, the function name (case sensitive) is the path to the resource in the URL.

Usage

You use this attribute to set the URL to a resource. A URL to, for example, the "users" resource is specified as follows:
WSPath="/users"
Note: The WSPath string begins with a slash (/), and there is a slash between each path element and/or template value.
If you need to specify a resource within a collection, such as a specific user identified by ID, and when a pattern could match many similar resources, it is specified with a path template.
WSPath=/users/{id}

The path template is an identifier enclosed in curly brackets {}. Zero, one, or several path templates can be specified. Values are substituted when a GWS client makes a call to the resource.

Path template values are provided at runtime in function parameters which have WSParam attributes. As many template values as path templates must be specified. In other words there must be a function parameter with a WSParam attribute to match each template path. fglcomp checks to ensure that there is one template value per parameter, otherwise compilation error-9111 is thrown.

You set the WSPath attribute in the ATTRIBUTES() clause of the function.

Example path templating with WSParam

TYPE accountType RECORD ... END RECORD

PUBLIC FUNCTION getAccountById(id INTEGER ATTRIBUTE(WSParam))

  ATTRIBUTES(WSGet,
    WSPath="/accounts/{id}",
    WSDescription="Returns an account record",
    WSThrows="404:not found"
  )
  RETURNS accountType ATTRIBUTES(WSName="Account",WSMedia="application/xml") 
    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://myhost:6394/gas/ws/r/myGroup/myXcf/MyService/accounts/4