API – Communication Between Systems

How do applications exchange data, and how can API be used to integrate different systems?

See API Integration in TAKZ MS

What Is an API?

API (Application Programming Interface) is an interface that allows different applications, services, or systems to communicate with each other. Through an API, one application can retrieve data from another application, send information to it, or perform specific operations without requiring direct access to its internal implementation.

What Is an API?

API Is Not a Communication Protocol

An API defines how a program can access specific functions or data. The API itself can be implemented using different technologies. In web-based systems, HTTP is very commonly used. The client sends a request to the server, and the server returns a response. HTTP uses a client-server model in which communication takes place through requests and responses.

API Is Not a Communication Protocol

Simplified Communication Flow

text
APPLICATION A
    │
    │  HTTP Request
    │  GET /api/events
    ▼
┌───────────────┐
│   API / HTTP  │
│    SERVER     │
└───────────────┘
    │
    │  HTTP Response
    │  JSON
    ▼
APPLICATION A

Requests and Responses

Typical API communication consists of a request sent by the client and a response returned by the server. A request may contain an HTTP method, resource address, headers, and, depending on the method, data sent in the request body. A response contains, among other things, a status code, headers, and optionally data.

Requests and Responses

Common HTTP Methods

GET

Primarily used to retrieve data or a representation of a specific resource.

POST

Used to send data to the server and may result in a change of server state or the execution of a specific operation.

PUT

Can be used to replace the representation of a specific resource with the supplied data.

PATCH

Used to partially modify a resource.

DELETE

Used to remove a specific resource.

GET – Retrieving Data

GET is one of the most commonly used methods when working with APIs. The client specifies the resource it wants to retrieve, and the server returns a response. An example request may look like this:

GET – Retrieving Data

GET Request Example

http
GET /api/events HTTP/1.1
Host: example.com
Accept: application/json

POST – Sending Data

POST allows data to be sent to the server. It is often used when a client wants to create data, submit an event, or trigger an operation on the server.

POST – Sending Data

POST Request Example

http
POST /api/events HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "message": "Test event",
  "priority": 1
}

JSON – A Popular Data Exchange Format

JSON (JavaScript Object Notation) is very commonly used to exchange data between applications. Its structure is easy for both humans and software to read. JSON can represent objects, arrays, strings, numbers, boolean values, and null.

JSON – A Popular Data Exchange Format

Example API Response in JSON

json
{
  "device": "Main Server",
  "datapoint": "CPU Usage",
  "value": 42.5,
  "state": "normal"
}

API Data Can Have a Nested Structure

An API response does not have to contain only a single value. It can consist of multiple fields, objects, and arrays. This allows a single datapoint to use a specific part of a larger response. Depending on the API implementation, individual fields can be accessed through successive object keys.

API Data Can Have a Nested Structure

Example of Nested Data

json
{
  "device": {
    "name": "Server 01",
    "status": {
      "state": "normal",
      "message": "System working correctly"
    }
  }
}

HTTP Headers

Headers allow additional information to be sent with a request or response. They can specify, among other things, the expected data format, the type of content being sent, or information required for authentication.

HTTP Headers

Example of a Token Header

http
GET /api/events HTTP/1.1
Host: example.com
Accept: application/json
Authorization: Bearer YOUR_TOKEN

API and Security

If an API provides data or functions that should be restricted, the server may require authentication. One common approach is to provide a token in an HTTP header. When communicating over the internet, HTTPS should also be used to protect transmitted data from interception.

API and Security

API as an Integration Layer

One of the main advantages of an API is the ability to connect different systems without directly modifying their internal structure. One system can provide data, another can process it, and a third can present it to users. An API can therefore act as a communication layer between existing solutions.

API as an Integration Layer

Example of System Integration

text
SYSTEM A
  │
  │  API / HTTP
  ▼
TAKZ MS
  │
  ├── Datapoints
  ├── Thresholds
  ├── States
  ├── Events
  └── Dashboard
  │
  │  API / HTTP
  ▼
SYSTEM B

API in TAKZ MS

In TAKZ MS, HTTP communication can be used to integrate external systems. Data retrieved from an API can be assigned to datapoints and then used for visualization, thresholds, states, triggers, and events. TAKZ MS can also send data to other systems using HTTP requests.

API in TAKZ MS

Receiving and Sending Data

Integration can work in both directions. TAKZ MS can retrieve information from an external API, but it can also send information to other applications. This allows datapoints to be used as communication elements between different systems.

Receiving and Sending Data

API Integration in TAKZ MS

A Practical Example

In the video above, we demonstrate practical API integration in TAKZ MS. The example includes retrieving data using GET, sending data using POST, working with JSON, visualizing datapoints, and using tokens to secure communication.

A Practical Example

Where Can APIs Be Used?

Monitoring

Retrieving information about the status of devices, services, and systems.

System Integration

Exchanging information between independent applications.

Automation

Triggering specific operations based on data or events.

Dashboards

Retrieving data from different sources and presenting it in one place.

Security Systems

Transferring alarms and events between different systems.

IoT and Automation

Exchanging data between devices, services, and higher-level systems.

API Does Not Mean Replacing an Entire System

In practical deployments, there is often no need to replace existing applications. If a system provides an API, it can be used to retrieve the required data or send information to the existing solution. This allows new functionality to be added as an additional integration layer.

API Does Not Mean Replacing an Entire System