.. _SystemIntegration_Intro: ############ INTRODUCTION ############ The RestAPI is a webservice that facilitates the integration of hardware devices and gateway applications provided by Alphatronics in a 3th party software solution. A device is represented as a resource and the device's features (LEDs, barrier, digital inputs, digital outputs, ...) are available through a set of data contracts. Each data contract consists of a set of methods defined for a specific feature of the device. A device can have one or more data contracts. For example: The STID reader can read barcodes and rfid tags, but it also has LEDs and a buzzer on board. This device has three data contracts: - :ref:`Barcodescanner ` : represents the barcode reader - :ref:`RFIDScanner ` : represents the rfid reader - :ref:`Indicators ` : represents the RGB leds and buzzer. The webservice is a REST based API that uses JSON as data exchange format and HTTPS with OAuth2.0 to exchange the data. The OAuth2.0 client credentials flow must be used and a JSON webtoken must be requested before access is granted to the api's methods. The webservice also supports the websocket protocol for unsolicited hardware messages (eg: digital input, barcode presented,...). See :ref:`websockets ` for more info. Specifications ************** * Runs on-premise inside a docker container (linux arm32 / windows X64) on an iot edge controller delivered by Alphatronics * Installed and configured through ALIOT (IoT platform of Alphatronics) - Deployment based on Azure iot edge modules. No incoming connections (eg: port forwarding rules) are required. * REST based API * JSON as data exchange format * HTTPS * OAuth2.0 client credentials flow for authorization (uses JSON access token) * Websocket support for hardware device events Deployment ********** The webservice is running in a docker container. This container can currently only be deployed through ALIOT. ALIOT is the Iot cloud solution of Alphatronics. It allows monitoring and configuration of iot edge controllers. Getting started *************** Api endpoint ============ The api is hosted on port 7081. Ping ==== To test if the API is running, send the following request (using a tool like postman or curl) : **URL parameters** * **hostIp**: Ip address of the API host. .. http:get:: https://{hostIp}:7081/ping **Example request**: .. sourcecode:: http POST /ping HTTP/1.1 Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 { "name": "(Gateway) Rest API", "apiVersion": "24.1.0.1", "runtimeArchitecture": "Arm", "clr": "v4.0.30319", "timestamp": "2022-08-16T11:30:02.9185377Z" } :statuscode 200: OK :statuscode 400: Bad Request. A descriptive error comes along with this error. :statuscode 500: Internal Server Error :resheader Content-Type: defines the serialization format for the response body (this depends on the :mailheader:`Accept` header of the request) :>json string name: api name :>json string apiVersion: version of the api :>json string runTimeArchitecture: hardware platform the api is running on. (eg: Arm, X64) :>json string clr: .net core CLR version :>json string timestamp: current date/time of the host the api is running on. Api versions ============ The api supports a header based versioning scheme. To use a specific version of the api, add the **x-api-version** header to the request, together with the desired api version number. Currently, the following api versions are available: **1**, **2** (unsupported). If no header is presented, the default version (currently version 1) is used. Testing ======= **Testing api methods** The api hosts a swagger ui auto-generated test webpage that can be found at: :: https://{hostIp}:7081/swagger/index.html .. note:: Note that a swagger.json OpenAPI specification document can be downloaded on this page. This document can then be imported by an api code generator to generate client side code or a REST API test tool (eg: postman) for evaluation. **Testing websocket messages** The latest version of `postman `_ supports websocket apis and can be used to test device messages sent through a websocket. Go to the :ref:`websockets ` page, to find about more about the websocket support. Security ======== Go to :ref:`security ` to learn more about how to request a web token for a certain role before calling the api's protected methods. Data contracts and devices ========================== Select a data contract in the **Contracts** section in the sidebar to learn more about the specific methods for a certain contract. Navigate to :ref:`supported devices ` to find out more what devices are supported by the api and which data contracts a device supports.