REST API Reference
Stereotype Attributes
REST API
Stereotype REST API is to used define a REST API for a Designer service.
Tagged Value | Description | Allowed Values | ||
---|---|---|---|---|
port | Defines the machine port number the service is binding to. | any number | ||
tracePort | Defines the shadow port of the service used for tracing. | any number (default is service port + 40000) | ||
maxRequestBodySize | Specifies the maximum size of the request in KB (1 KB = 1024 Bytes). This can be used to prevent DoS or similar attacks. When the payload of the service exceeds the given maximum, incoming request are rejected. | any positive integer | ||
0 | Accept unlimited requests (default of services compiled with Builder versions < 7.12.0). | |||
2048 | 2MB, default if not specified | |||
maxRequestHeaderSize | Specifies the maximum size of the request header in KB (1 KB = 1024 Bytes). This can be used to prevent DoS or similar attacks. When the header payload of the service exceeds the given maximum, incoming request are rejected. | any positive integer | ||
8 | 8 KB (default if not specified). | |||
maxParallelConnections | Defines the maximum number of request that can be processed in parallel. | any positive integer | ||
tokenType | Mark the service as to use token authorization. The REST Test Tool (API Management) will then present a field to enter the token and put the value into the HTTP headers. Refer also to tokenHeaderName for more information. You can use both in a REST service: basic authorization and token authorization, see useBasicAuth. | none | Do not use token authorization. | |
API Key | Use API key authorization. | |||
tokenHeaderName | Defines the name of the header that will transport the token. This tagged value is only relevant, if token authorization is enabled at all. The token header name will be presented as the name of the header field that can be entered in the Bridge REST Test Tool. Refer also to tokenType for more information. | A valid HTTP header name (according to RFC2616/RFC7230). | ||
useBasicAuth | Mark the service as to use basic authentication mechanisms. The REST Test Tool (API Management) will then present fields to enter the credentials and put the values into the HTTP headers. You can use both in a REST service: basic authorization and token authorization, see tokeType and tokenHeaderName. | true | Enable basic authentication. | |
false | Disable basic authentication (default). | |||
jsonKeepNulls | When jsonKeepNulls is true, attributes of the REST response object having NULL values will be rendered to the REST response, otherwise they will be left out completely (see also chapter NULL Values). | true | Render attributes with NULL values to the REST response. | |
false | Leave out attributes with NULL values in the REST response (default). | |||
jsonCompact | When jsonCompact is true, the JSON composer will generate compact JSON, otherwise it will generate pretty JSON. | true | Generate compact JSON (default). | |
false | Generate pretty JSON. | |||
jsonWriteTypeDiscriminator | If jsonCompact is true, the JSON composer will generate xUML type properties ("e2e:type") to the generated JSON. If this option is true, the Runtime will write the original xUML type to the generated JSON in form of | true | Write xUML type discriminator. | |
false | Do not write xUML type discriminator. |
REST Port
Stereotype REST Port is used on a class to mark it as REST port, the root element of a REST service structure.
Tagged Value | Description | Allowed Values | |
---|---|---|---|
path | Defines the path to this rest interface. If empty, the path is derived from the package structure. | none | path of the package structure will be used, e.g. |
any valid path string | path string starting with "/", e.g. | ||
errorClass | Assigns a user-defined RESTError class to the REST interface. This class should be set in case of error and given back via the REST response. | any complex type describing the structure of the error | |
apiVersion | Defines the API version this port type provides (for documentation purposes only). | any string, default is 1.0.0 |
REST Resource
Stereotype REST Resource is used on a class to mark it as REST resource, part of a REST service structure.
Attribute | Description | Allowed Values | |
---|---|---|---|
Relative Path | Defines the path of the REST resource or collection in relation to the parent resource. You can provide a static path, or a dynamic path using the notation | none | the name of the REST resource will be used, e.g. /supportcases |
any valid string | the given name will be used | ||
a dynamic path supplying a REST parameter | dynamic path, the value of the REST parameter will be passed to the REST methods, e.g. :id | ||
Is Verbatim Path | Disable most of the path normalization. All escaping must be done manually, leading or trailing whitespaces are preserved.
| true | Path should be treated as verbatim, path normalization is disabled. |
false (default) | Path should be URL encoded. |
REST
Stereotype REST is used on a REST resource class method to mark it as REST method, part of a REST service structure. If the method name is one of GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS (with optional trailing '/'), it will be invoked automatically on its parent resource when an corresponding request is received.
Refer Implementing REST Methods to for more details and some examples.
Attribute | Description | Allowed Values | |
---|---|---|---|
Http Method | Provide the HTTP method of this REST method should respond to. | a valid HTTP method | GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS |
none |
| ||
Relative Path | Defines the path of the REST method in relation to the parent resource. | none | The name of the REST method will be used. |
any valid string | The given name will be used. The relative path may also contain variables (REST path parameters, specified as :<variable name>) and can be segmented like e.g. /date=:<a date variable> . | ||
Is Verbatim Path | Disable most of the path normalization. All escaping must be done manually, leading or trailing whitespaces are preserved.
| true | Path should be treated as verbatim, path normalization is disabled. |
false (default) | Path should be URL encoded. | ||
Blob Body Content Type | Specify a content type for Blob response parameters from this endpoint. This must be a valid "accept" header as defined in RFC 7231. This attribute must be left unset if no Blob output parameters are used. In future versions, the effect of this attribute may be extended to other contexts as well. | a list of valid media ranges | e.g. image/png |
Reject Other Response Content Types | The xUML Runtime performs a verification of the "accept" header for REST responses. Specify whether to return an error (HTTP 406, not acceptable) on requests with an "accept" header that does not conform with the content types specified in Blob Body Content Type. | true |
|
false | Accept the request in spite of the mismatch and handle this within the service. | ||
Accepted Request Content Types | Provide a list of content types this REST endpoint accepts. This must be a list of valid "accept" headers as defined in RFC 7231. This attribute must be left unset if no Blob output parameters are used. In future versions, the effect of this attribute may be extended to other contexts as well. | a list of valid media ranges | e.g. image/png;image/jpeg |
Reject Other Request Content Types | Specify whether to return an error on requests with a content type that does not conform with the content types specified in Accepted Request Content Type. | true |
|
false | Perform the adapter call in spite of the "content-type" header mismatch and handle this within the service. |
REST Parameter
Stereotype REST Parameter is used on a REST method parameter to mark it as REST parameter. Refer to REST Parameters to for more details and some examples.
Tagged Value | Description | Allowed Values | Allowed REST Methods | Allowed Types | Hints and Limitations | |
---|---|---|---|---|---|---|
In | Defines how the parameter will be passed to the REST method. This tag is mandatory. | query | via a query string | all | all simple types and Array of simple type | Unknown parameters will be ignored, known will be passed to the method after being URL-decoded. |
path | via the REST resource path | all | Integer, Float, String, Boolean, DateTime | Path parameters are all required. All path parameters must be consumed by the called method and the parameter names must be the same as the path segment identifiers (without colon). | ||
body | via the REST call body | POST, PUT, PATCH | a complex type and Array | A REST method can have only one body parameter. | ||
header | via the REST call header | all | all simple types and Array of simple type | Unknown parameters will be ignored, known will be passed to the method. | ||
External Name | Defines an external name for the REST parameter. | any string | Use this, when wanting to access a REST service that has parameter names with special characters. In this case, set this name (e.g. |
REST Error
Stereotype REST Error is used on a class to mark it as REST error class. Assign such a class to the REST port (see REST Port) and this class will be used as output in case of error. Each REST port can have its separate error class.
You can report errors back to the caller using something like:
local response = getRestHttpResponse();
response.responseObject = <my error object>;
response.httpStatus = <a matching http error code>;
REST Content Types
The xUML Runtime handles content types as follows:
Content Type Header | Accept Header | Runtime Behavior | Assumed Content Type | HTTP Header Code |
---|---|---|---|---|
/ | If the Content-Type header is set, the xUML Runtime will assume that the request is of that type. All other request will be rejected (HTTP error code 406). | Content-Type header | 406 | |
If no Content-Type header is set, but the Accept header is, the xUML Runtime will deduce the request type from it. All other request will be rejected (HTTP error code 406). | Accept header | 406 | ||
In absence of both headers, the Runtime will assume JSON. All other request will be rejected (HTTP error code 415). | JSON | 415 |
The full matching is done in a "best effort" manner. Given the type format <type>/<subtype>[+<suffix>][; paramName=paramValue]*
, the xUML Runtime first disregards the type and parameters. Then it checks, if the subtype is JSON or XML. If the subtype doesn't match with the supported types, it tries the suffix.
REST Adapter Parameters
Name | Type | Direction | Description |
---|---|---|---|
requestOptions | in | Use this parameter to configure the REST Adapter dynamically and overwrite the settings from the component diagram. | |
response | Any | out | This parameter holds the adapter output and is of that type that is given back by the called REST service. |
REST Utility Functions
Access to HTTP request and response objects is provided through global methods: getRestHttpRequest()and getRestHttpResponse().
Function | Parameter | Return Value | Description | Example |
---|---|---|---|---|
getRestHttpRequest() | none | object of type Request | Returns the request details as provided by the HTTP call. Changing the request object will not have any effects. |
|
getRestHttpResponse() | none | object of type Response | Set the response details to return them to the caller. |
|
getRestHttpRequest() returns the headers in REST service context. In other contexts, e.g. if called via a SOAP shadow port (and thus SOAP context), getRestHttpRequest() will return NULL
. Use getServiceContext() or getServiceContextValue() in such cases.
REST Parameter Types
Request
Attribute | Type | Description | Values/Example |
---|---|---|---|
method | HTTP method used in call. |
| |
queryString | String | Query string, if provided with the call. |
|
queryParameters | Array of Parameter | All query parameters as an array of Parameter classes containing name/value pairs. | |
body | Blob | Body of the HTTP request. | |
path | String | Path to the REST resource. |
|
pathParameters | Map | All REST parameters as a map. | |
httpHeaderMap | Map of Entry | Header information as a map. The map contains arrays of header value strings whereas the header name is the key of the map.
Refer to HTTP Header Support for more information on the standard xUML HTTP headers. |
Response
Attribute | Type | Description | Values/Example |
---|---|---|---|
headers | Array of HeaderField | All HTTP response header fields as an array of HeaderField classes containing name/value pairs. | |
statusCode | Integer | The resulting HTTP status code. If not set explicitly using this object, the service returns 200 if no exception occurred, or 500 otherwise. |
|
errorObject | Any | Object of the type defined with stereotype RESTError. |
RequestOptions
Attribute | Type | Description | Allowed Values / Examples | |
---|---|---|---|---|
additionalHeaders | Array of HeaderField | All REST request header fields as an array of HeaderField classes containing name/value pairs. | ||
options | Array of Option | Specify native cURL options as listed in Setting cURL Options on the URL Adapter. Use one of the following syntax rules:
| ||
ssl | Use this parameter to supply SSL information. | |||
proxy | Use this parameter to supply necessary proxy information. | |||
additionalQueryParameters | Array of Parameter | Use this parameter to provide additional query parameters to the REST service call. | ||
followRedirects | Integer | Specify here the maximum number of redirects to follow. Default value is 0 (no redirects). | any integer | |
basicAuth | This parameter provides an object of type Authentication containing the user and the password. | |||
basePath | String | Overwrite here the base path of the REST service. | a valid path, e.g. /support | |
host | String | Overwrite here the host running the REST service that has been defined in the component diagram. | a valid host, e.g. scheer-acme.com | |
port | Integer | Overwrite here the port through which the REST service is accessible. | a valid port number, e.g. 12345 | |
protocol | String | Overwrite here the protocol through which the REST service is accessible. | http | Use the HTTP protocol to access the service (default). |
https | Use the HTTPS protocol to access the service. | |||
ignoreHttpErrors | Boolean | If true, Default value is true. | true | HTTP error codes >= 400 will not cause an exception in the service (default). This implies, that the response body is accessible even if HTTP errors occur. |
false | HTTP error codes >= 400 will cause an exception in the service. | |||
jsonComposerOptions | Use this parameter to specify JSON composer options on the REST call. You can use these options to e.g. overwrite jsonKeepNulls from the REST alias. | Valid composer options as described below. |
AdapterResponse
Attribute | Type | Description | Values/Example |
---|---|---|---|
httpStatus | Integer | HTTP status code of the adapter call. | 500 |
headers | Array of Header Field |
This attribute is deprecated. It is only present for compatibility reasons. Please use httpHeaderMap for new implementations. The implementation of httpHeaderMap complies to the HTTP specification and supports multiple headers having the same name. | |
body | Blob | HTTP body of HTTP response. | |
responseObject | Any | Response Object of the REST adapter call.
| |
httpHeaderMap | Map of Entry | Header information as a map. The map contains arrays of header value strings whereas the header name is the key of the map.
Refer to HTTP Header Support for more information on the standard xUML HTTP headers. |
Request and Response Types
REST Type | Attribute | Type | Description | Values/Example |
---|---|---|---|---|
Authentication | username | String | Username. | |
password | String | Password. | ||
Certificate | file | String | Certificate file. | |
type | String | |||
ComposerOptions | keepNulls | Boolean | Keep | |
Entry | key | String | Key of the map entry. | |
value | Array of Any | List of values of the map entry. The dynamic type for httpHeaderMap is String. | ||
HTTPMethod | enumeration | List of all valid HTTP methods |
| |
HeaderField | name | String | Name of the header field. | |
value | String | Value of the header field. | ||
Option | name | String | Name of the option. | |
value | String | Value of the option. | ||
Parameter | name | String | Name of the parameter. | |
value | String | Value of the Parameter. | ||
Proxy | url | String | URL. | A valid URL. |
type | String | |||
authentication | See above. | |||
SSL | verifyPeer | String | ||
verifyHost | String | |||
caInfo | String | |||
certificate | See above. | |||
key | Key |
RESTAdapter_SupportManager_Example
Click there to download a simple example model that shows the usage of the REST adapter in Scheer PAS Designer.
RESTAdapter_BlobContent_Example
Click here to download a simple example model that shows how to handle Blob content with a REST call in Scheer PAS Designer.