Logger: Create RESTful Data Services
Although LOC data processes are not built and run exactly like microservices (containered applications), they are versatile enough for creating similar functionalities, and can be deployed or revisied quickly thanks to their serverless nature.
Here we will learn how to create two simple RESTful services that can read or wrote user logs in a database.
-
To create two data process that can read and write a database table with RESTful-like input and output.
-
To create reusable logic modules and to control their behavior using logic variables.
-
To create an agent configuration for
-
To create multiple API routes as the RESTful API endpoints.
Data Service Design
Database Table Schema
For this tutorial, we will create a simple table Log
in the database (for which we will use Microsoft SQL Server as the example) with the following fields:
Field | Type |
---|---|
ID | INT IDENTITY NOT NULL |
Message | Text |
Timestamp | DATETIME |
IDENTITY
in Transact-SQL is equivalent to AUTO_INCREMENT
in other SQL variations.
Create or Drop Log Table in MS SQL Server
Create table
CREATE TABLE dbo.Log (
ID INT IDENTITY NOT NULL,
Message TEXT,
Timestamp DATETIME
);
GO
The table name is dbo.Log
since dbo
is the default schema for all tables in SQL Server.
Delete all rows in table
DELETE FROM dbo.Log;
GO
Be noted that delete the table content will not reset the auto increment value of ID
.
Drop Table
DROP TABLE dbo.Log;
GO
To reset the auto increment value of ID
, drop (remove) the table then create it again.
API Endpoints
We will create two RESTful-like APIs to read and write the Log
table:
Method | API path | Description | Input |
---|---|---|---|
POST | /api/data-service/v1/logs | Write logs | JSON payload |
GET | /api/data-service/v1/logs?limit={n} | Query logs with maximum limit of n | Querystring |
- POST Log API
- GET Log API
Input
{
"logs": ["Life, Universe and Everything", "42", "Don't Panic"]
}
The POST data service will throw an error or exception if no logs are provided in the payload.
Response
{
"status": "ok",
"statusCode": 201,
"timestamp": "2024-01-01T12:00:00.000000000Z",
"result": {
"affectedRowCount": 3
}
}
Input
?limit={n}
n
will be set to 1000
if no valid parameter is provided in the querystring.