Service Declaration
All micro-services declarations for the Avid Platform are provided in JSON format. Here is example of the service contract
1 | { |
Service Contract Anatomy
Root JSON object of the service contract has the following fields:
Field Name | Type | Description | Is Required | Default |
---|---|---|---|---|
serviceType | string | unique name given to each service | true | n/a |
serviceRealm | string | realm, where this service is available | false | “global” |
serviceVersion | integer | version of the service | true | n/a |
description | string | detailed description of the service | false | empty string |
compatibleVersions | array | array of integers, providing list of service versions which are compatible with current version | false | n/a |
scope | string | one of two values “zone” or “multi-zone”, declare if service must be accessible from zone where it is running only or from any zone | false | “zone” |
ops | object | list of service operations | false | {} |
errorCodes | object | list of errors, which service may return | false | {} |
Service Operations
Service operations object contains unique fields. Field names are representing names of service operations provided by given service. In the following example, two operations are provided in the “ops” object: “add” and “divide”.
1 | { |
Examples
Each operation object has the following fields:
Field Name | Type | Description | Is Required | Default |
---|---|---|---|---|
description | string | description of the service operation | false | empty string |
examples | object | list of usage examples for the given operation | false | {} |
rest | object | REST endpoint definition for the given operation, if operation must be exposed for HTTP access via Avid Upstream | false | {} |
Examples object is providing list of usage examples for the given operation. Field names of the examples object are representing example names. Value of each example object is sample message corresponding to example. In the following code block we have two examples of service operation usage. One named “normal divide” another named “division by zero”. For message parameters, both examples are taking object with two fields “num1” and “num2” with different values.
1 | { |
REST Endpoint
If service must expose access to service operation(s) via HTTP REST, to be accessible through the Avid Upstream, it must provide REST declaration for such operation(s). Rest object has the following fields:
Field Name | Type | Description | Is Required | Default |
---|---|---|---|---|
path | string | HTTP path to the service operation | true | n/a |
method | string | HTTP method to be invoked (GET, POST, DELETE etc) | false | GET |
queryParams | array | array of query parameters | false | [] |
Path may contain dynamic parts, parameter name in the curly brackets, like “instances/{instanceId}/health”. In this case value of instanceId will be extracted from the path and passed in the message.
Error Codes
If service going to return errors back to sender under some circumstances, it must register these errors in the “errorCodes” object. Field names of the “errorCodes” object are representing error codes registered with the service. Each error code is the object, with the following fields:
Field Name | Type | Description | Is Required | Default |
---|---|---|---|---|
description | string | description of the error | false | empty string |
status | integer | valid HTTP status that can be used by Avid Upstream | true | |
severity | string | a syslog style log level: EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG | true | |
messageTemplate | string | error message template in en_US locale that may include %{ |
true |