API Reference
Base Configuration
Base URL: http://localhost:8080
Content-Type: application/json
CORS: Enabled for http://localhost:3000
Data Endpoints
GET /api/data
Query city data với pagination và filtering.
Request:
GET /api/data?type=HOT&sensorId=SENSOR_0042&page=0&size=20
Query Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | No | All | Filter by data type: HOT, WARM, COLD |
sensorId | string | No | All | Filter by sensor ID |
page | integer | No | 0 | Page number (0-indexed) |
size | integer | No | 20 | Page size (max 100) |
Response: 200 OK
{
"data": [
{
"timestamp": "2025-12-04T22:57:00Z",
"sensorId": "SENSOR_0042",
"metricType": "temperature",
"value": 45.5,
"dataType": "HOT",
"location": {
"lat": 21.0285,
"lng": 105.8542
}
}
],
"page": 0,
"size": 20,
"total": 150,
"totalPages": 8
}
Statistics Endpoints
GET /api/stats
Lấy thống kê hệ thống real-time.
Request:
GET /api/stats
Response: 200 OK
{
"hotCount": 14250000,
"warmCount": 0,
"coldCount": 25750000,
"incomingRate": 487.5,
"processedRate": 487.5,
"lastUpdate": "2025-12-04T22:57:00Z"
}
Fields:
| Field | Type | Description |
|---|---|---|
hotCount | long | Số lượng messages trong HOT tier (Redis) |
warmCount | long | Số lượng documents trong WARM tier (MongoDB) |
coldCount | long | Số lượng documents trong COLD tier (MongoDB) |
incomingRate | double | Message rate incoming (msg/s) |
processedRate | double | Message rate processed (msg/s) |
lastUpdate | string | Timestamp của stats update |
Edge Storage Management Endpoints
GET /api/nodes
Liệt kê tất cả Edge Storage nodes với thông tin chi tiết.
Request:
GET /api/nodes
Response: 200 OK
[
{
"id": "subnet-caugiay",
"name": "Subnet-CauGiay",
"host": "rabbit-edge-1",
"port": 5672,
"enabled": true,
"status": "online",
"lastPing": "2025-12-07T23:30:00Z"
},
{
"id": "subnet-thanhxuan",
"name": "Subnet-ThanhXuan",
"host": "rabbit-edge-2",
"port": 5672,
"enabled": true,
"status": "online",
"lastPing": "2025-12-07T23:30:00Z"
}
]
Fields:
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier (lowercase, hyphenated) |
name | string | Display name của edge node |
host | string | Hostname hoặc IP address của RabbitMQ |
port | integer | Port number của RabbitMQ |
enabled | boolean | Trạng thái kích hoạt của node |
status | string | Trạng thái kết nối: "online" hoặc "offline" |
lastPing | string | Timestamp của lần ping cuối cùng |
POST /api/nodes
Tạo mới một Edge Storage node.
Request:
POST /api/nodes
Content-Type: application/json
{
"name": "Subnet-HaDong",
"host": "rabbit-edge-3",
"port": 5672,
"queueName": "city-data-queue-3",
"username": "edge_user",
"password": "edge_pass"
}
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Tên edge node (VD: "Subnet-HaDong") |
host | string | Yes | Hostname của RabbitMQ |
port | integer | Yes | Port number (thường là 5672) |
queueName | string | No | Tên queue (auto-generated nếu không cung cấp) |
username | string | No | RabbitMQ username (mặc định từ config) |
password | string | No | RabbitMQ password (mặc định từ config) |
Response: 201 Created
{
"id": "subnet-hadong",
"name": "Subnet-HaDong",
"host": "rabbit-edge-3",
"port": 5672,
"status": "online",
"enabled": true
}
Error Response: 409 Conflict
{
"error": "Node with name 'Subnet-HaDong' already exists"
}
PUT /api/nodes/{name}/toggle
Toggle trạng thái enabled/disabled của một edge node.
Request:
PUT /api/nodes/Subnet-CauGiay/toggle
Response: 200 OK
{
"name": "Subnet-CauGiay",
"enabled": false,
"status": "offline"
}
DELETE /api/nodes/{name}
Xóa một edge node khỏi hệ thống.
Request:
DELETE /api/nodes/Subnet-HaDong
Response: 200 OK
{
"message": "Node deleted successfully",
"name": "Subnet-HaDong"
}
Error Response: 404 Not Found
{
"error": "Node 'Subnet-HaDong' not found"
}
System Control Endpoints
POST /api/sync/trigger
Trigger manual data synchronization từ tất cả edge nodes.
Request:
POST /api/sync/trigger
Response: 200 OK
{
"status": "success",
"messagesProcessed": 5247,
"timestamp": "2025-12-04T22:57:00Z"
}
POST /api/system/reset
⚠️ DESTRUCTIVE - Xóa toàn bộ dữ liệu (demo purpose only).
Request:
POST /api/system/reset
Response: 200 OK
{
"status": "success",
"message": "All data cleared successfully",
"timestamp": "2025-12-04T22:57:00Z"
}
Health Check
GET /actuator/health
Spring Boot Actuator health endpoint.
Request:
GET /actuator/health
Response: 200 OK
{
"status": "UP"
}
Error Responses
400 Bad Request
{
"error": "Invalid parameter",
"message": "Page size must be between 1 and 100",
"timestamp": "2025-12-04T22:57:00Z"
}
500 Internal Server Error
{
"error": "Internal server error",
"message": "Failed to connect to MongoDB",
"timestamp": "2025-12-04T22:57:00Z"
}