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:

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 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.

GET https://{hostIp}:7081/ping

Example request:

POST /ping HTTP/1.1
Accept: application/json

Example response:

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"
}
Status Codes:
Response Headers:
  • Content-Type – defines the serialization format for the response body (this depends on the Accept header of the request)

Response JSON Object:
  • name (string) – api name

  • apiVersion (string) – version of the api

  • runTimeArchitecture (string) – hardware platform the api is running on. (eg: Arm, X64)

  • clr (string) – .net core CLR version

  • timestamp (string) – 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 websockets page, to find about more about the websocket support.

Security

Go to 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 supported devices to find out more what devices are supported by the api and which data contracts a device supports.