WSVersion (function)

Specify version in the REST service via a version name.

Syntax

WSVersion = "{ version } [,...]"
Where WSVersion is a comma-separated list of versions and where:
  1. version defines the version of the operation.

WSVersion is an optional attribute.

Usage

You use this attribute to specify version at the function level. It activates versioning for the Web service.

Set a version name on the WSVersion attribute in the ATTRIBUTES() clause of the REST function. By doing this you specify the version of the Web service in which the operation will be accessible to clients.

You can use this attribute to update a previous version of the same operation (with the same path and verb) to a new version of the operation. Existing versions are not affected and can still be used.

If you have an operation that is static and does not change from version to version, you do not need to set a version for it, or you can set its WSVersion attribute with the value "default". It will then be used by default in all versions unless the GWS finds a version of the operation when a client requests a specific version.

When an operation is accessible in one or more versions, you can set these specifically within the attribute, for example, WSVersion="v1,v2,v3".

You can display the documentation for a specific version of the Web service, by adding the query "&version=nameVersion" in the URI. For example: http://myhost:6394/ws/r/fruits?openapi.json&version=v2

Example setting WSVersion in functions

In the example, the function "prices_default" is set as the default version of the prices operation. There are two different versions of operations defined for the Web service, "v2" and "v3".

When you generate the OpenAPI documentation for version 3, for example, http://myhost:6394/gas/ws/r/myGroup/myXcf/myService?openapi.json&version=v3, the GWS will select the "prices_default" operation in v3.

In requests for version 2, as a version of the function is available, the GWS will select the "prices_v2" operation.

PUBLIC FUNCTION prices_default(nb INTEGER ATTRIBUTE(WSParam))
 ATTRIBUTES (WSGet,WSPath="/prices/{nb}",WSVersion="default")
 RETURNS (INTEGER)
  DEFINE price INTEGER
   # function code ...
  RETURN price
END FUNCTION
PUBLIC FUNCTION quantity_v3()
 ATTRIBUTES (WSGet,WSPath="/quantity", WSVersion="v3")
 RETURNS (INTEGER)
   DEFINE quantity INTEGER
   # function code ...
  RETURN quantity
 END FUNCTION
PUBLIC FUNCTION prices_v2(nb INTEGER ATTRIBUTE(WSParam))
 ATTRIBUTES (WSGet,WSPath="/prices/{nb}", WSVersion="v2")
 RETURNS (INTEGER)
  DEFINE price INTEGER
   # function code ...
  RETURN price
 END FUNCTION