RESTful Adapter Service
Documentation about an example of a RESTful api service that consumes a source adapter.
Last updated
Documentation about an example of a RESTful api service that consumes a source adapter.
Last updated
This documentation contains an overview of the Visual Studio solution and descriptions of all REST service calls. Additional to all calls an example request and response as json objects are explained and displayed.
Content of the solution:
The VS solution consists of three projects and one configuration:
TivityPluginService: WebAPI project, the actual plugin REST service
Tivity.Plugnis.Dummy: a example adapter serves inside the WebAPI as fallback adapter
Tivity.Plugins.RestService.Test: UnitTests for the REST Service project
docker-compose: the docker configuration, it is possible to start the service
in the container out of the service.
After you build the solution, the service starts and the homepage appears in the browser from the plugin service. The start page is an openAPI documentation like swagger.
This is a project created as a VS WebAPI project based on .NET core 2.1 and serves as the API interface for an adapter instance. This project is intended as example code for a REST Service which the TIVITY platform can communicate with. Of course, this service can also be used productively and a specially developed adapter connect and wrap. This adapter should be available as a Microsoft .NET assembly.
NOTE It can also be used a special developed adapter (e.g. Java). This must be identical to the interface used in the example service.
The service basically consists of the API controllers and the wrapper class. The controllers are the interfaces to "outside" while the wrapper ensures the communication "inside", namely to the adapter. In addition, there are the usual Startup and program classes for the service, which are used for the entry point. Further configurations are stored in the Dockerfile and appsettings.json.
The SourceController is a important API controller for the communication with the SourceAdapter. There, the SourceAdapter interfaces (ISourceAdapter, ISource) are implemented. These interfaces provide the configuration and adapter instantiation as API calls.
The interface for the adapter is defined like this:
The corresponding methods in the API Controller look very similar (simplified method body):
Except for Connect, all methods are asynchronous. And it is noticeable that another ActionResult type is given as a template. This is a standard Microsoft return type ActionResult<T>
for asp.net core. and was just added for comfortable response generation. This type is not necessary for your own service. Otherwise the methods correspond to those of the interface ISourceAdapter.
POST
https://adapterservice/api/source/connect
The connect method configured the adapter inside the service. The request consists a bulk of configurations in JSON format or what else.
json object
string
{
"configuration": "string"
}
Request example for a configuration of user and password:
POST
https://adapterservice/api/source/define
The define method returns the basic information of the adapter. Properties are name and description. Additionally a thumbnail can be added. The request for define method can also be empty.
json object
string
Empty request body.
GET
https://adapterservice/api/source/config
Starts the configuration process. Returns a configuration step with initial parameters. The parameters represent a form input on the platform configuration.
json object
string
Empty request body.
POST
https://adapterservice/api/source/config
Handle the configuration process. In the request object AdapterConfigHandleRequest a list of configuration parameters are send to the service. This parameters are the input values from a configuration form.
json object
string
{
"key": "string",
"parameters": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
}
In the adapter source you can now validate this parameter values. If the values are valid you returned a success step. Otherwise you send a configuration step back, similar the start conf method (further up). But at this time with error messages in failed parameter objects.
GET
https://adapterservide/api/source/capability
Get a list of capabilities which are supported by the source adapter (service).
json object
string
Empty request body.
The available capability types ar listed under the ISource topic.
For the adapter call with the method Execute, an ActionController exist with the same method. This controller has only this one method as well.
There are three properties in the ActionExecuteRequest.
parameter name
type
description
ClassName
str
Name of the class where action executed (optional)
ActionName
str
Name of the action, it could be multiple actions in adapter
Parameters
Dictionary
List of object, comparable with method parameters (key=param-name, value=object)
GET
https://adapterservice/api/action/execute
json object
string
example:
{
"className": "myClass",
"actionName": "myAction",
"parameters": {
"parameter1": "myValue",
"parameter2": { 3, 5 },
"parameter3": { "text 1", "text2" }
}
}
In this example response the object is a translation object, in property "value" (JSON):
The SchemaController has only one Method "Get" (HTTP POST). This method returns a list of schema definitions.
The SchemaGetRequest object is currently empty. For more information about the response object see the schema capability documentation.
POST
https://adapterservice/api/schema/get
Method for getting schema definition information.
json object
string
empty request body.
The QueryController has only one method and passes the request through to the adapter.
The QueryExecuteRequest object needs a Query with the class ("From"), the columns and a list of conditions. Optional we can add Joins and Paginations. You find a detailed description of the individual properties in the SourceAdapter Documentation.
POST
https://adapterservice/apiquery/execute
json object
string
serialized query object. See example below.
! Important: specify the expression type in json request.
Example request (json): For more information about the Query object see the SourceAdapter Documentation.
For manipulate an instance (or model) the ModelController is responsible. This controller has three methods: create, update and delete.
For more information about the model methods create, update and delete see the SourceAdapter Documentation about ModelCapability.
POST
https://adapterservice/api/model/create
To create a new instance of a class, the create method can be used.
json object
string
The request object needs a class name of an existing class and the new instance as a list of key-value pairs.
{
"className": "myClass",
"model": {
"property1": "value1",
"property2": "value2"
}
}
PUT
https://adapterservice/api/model/update
To manipulate an existing instance usually the update method is used. The ModelUpdateRequest needs the class name and a key for identify the model and the instance itself with all changed properties.
json object
string
- className: underlying class of the instance
- key: instance identifier
- model: properties which are updated
{
"className": "myClass",
"key": {
"propertyId": "identifier"
},
"model": {
"property1": "newValue1",
"property2": "newValue2"
}
}
DELETE
https://adapterservice/api/model/delete
For delete an instance (model) call the delete method. The request needs the class name and a key for identify the instance.
json object
string
- className: underlying class of the instance
- key: instance identifier
{
"className": "myClass",
"key": {
"propertyId": "identifier"
}
}
In order to obtain a document you have to use the Download method. As a result, only the content of a document is returned. This is a (byte) stream with the content type information in response header.
For better understanding of the method and the request object see chapter IDocumentCapability in SourceAdapter.
POST
https://adapterservice/api/document/download
For download a content you need to send the information about the class and a document identifier. These values are set in the DocumentDowloadRequest. The class name is useful to assign the document content to a certain class. The key value is required to uniquely identify a document. This identifier can be a unique name, a path or a GUID as well.
json object
string
- className: name of the assigned class (optional)
- key: unique identifier (requred)
{
"className": "NameOfClass",
"key": "identifier"
}
Example request (json):
When files need to be uploaded, the StorageController is also required. This controller ensures that the file stream and an identity key (FileId) are received on server site. The REST service provides for storage the file contents (streams) e.g. save on disk, in database or on memory cache.
POST
https://adapterservice/api/storage/upload
The upload request is a multipart/form-data content-type which consists of the file stream and the formdata FileId.
FileId
string
unique identifier of the file
(file) stream
object
the file stream
During the upload process the platform additionally trigger an execute call (see 3.2 ActionController). There is an entry in the 'parameters' dictionary with the file metadata or a list of files. For Details see the SourceAdapter documentation.
Example execute request for a list of files (json):
Upload asynchronous calls as sequence diagram:
It is essential for success uploading files that the upload method exist in the REST service and the adapter capability IActionCapability with the execute method was implemented as well. This execute method must be able to process the file parameters accordingly (see example request above).