-
Notifications
You must be signed in to change notification settings - Fork 1
Endpoints configurations
Apinan Woratrakun edited this page Jan 16, 2025
·
1 revision
ไฟล์ config/endpoints.json มีโครงสร้างดังนี้:
{
"endpoints": [
{
"name": "API Name",
"url": "https://api.example.com",
"method": "GET",
"schedule": "30s",
...
}
]
}| พารามิเตอร์ | ประเภท | คำอธิบาย | ตัวอย่าง |
|---|---|---|---|
| name | string | ชื่อของ endpoint (ต้องไม่ซ้ำ) | "User API" |
| url | string | URL ของ API | "https://api.example.com" |
| method | string | HTTP Method | "GET", "POST", "PUT", "DELETE" |
| schedule | string | ความถี่ในการเช็ค | "30s", "1m", "1h" |
| expectedStatus | number | HTTP status ที่คาดหวัง | 200, 201 |
"headers": {
"Authorization": "Bearer ${API_TOKEN}",
"Content-Type": "application/json"
}"input": {
"body": {
// สำหรับ POST, PUT requests
},
"params": {
// query parameters
}
}"validation": {
"responseTime": 5000,
"schema": {
// response validation schema
}
}{
"name": "Health Check API",
"url": "https://api.example.com/health",
"method": "GET",
"schedule": "30s",
"expectedStatus": 200,
"validation": {
"responseTime": 3000,
"schema": {
"status": {
"required": true,
"type": "string"
}
}
}
}{
"name": "Create User",
"url": "https://api.example.com/users",
"method": "POST",
"schedule": "1m",
"expectedStatus": 201,
"headers": {
"Authorization": "Bearer ${API_TOKEN}",
"Content-Type": "application/json"
},
"input": {
"body": {
"username": "test",
"email": "test@example.com"
}
}
}| รูปแบบ | คำอธิบาย |
|---|---|
| 30s | ทุก 30 วินาที |
| 1m | ทุก 1 นาที |
| 5m | ทุก 5 นาที |
| 1h | ทุก 1 ชั่วโมง |
| 1d | ทุก 1 วัน |
การตรวจสอบ response ด้วย schema:
"schema": {
"propertyName": {
"required": true,
"type": "string|number|boolean|object|array"
}
}- สร้างไฟล์
.envจาก.env-example - กำหนดค่า variables ที่จำเป็น เช่น API_TOKEN
- ตรวจสอบ JSON format ให้ถูกต้อง
- หลีกเลี่ยงการตั้ง schedule ที่ถี่เกินไป
- ระวังการเปิดเผยข้อมูลที่สำคัญใน input parameters
- ตรวจสอบ URL ให้ถูกต้องและมี protocol (http/https)
- ตั้งชื่อ endpoint ให้สื่อความหมาย
- กำหนด timeout และ responseTime ให้เหมาะสม
- ใช้ schema validation เพื่อตรวจสอบ response
- เก็บ sensitive data ไว้ใน environment variables
- ข้อมูล monitoring จะถูกเก็บที่
logs/monitor_logs.json - ข้อผิดพลาดจะถูกเก็บที่
logs/error_logs.json
- แก้ไขไฟล์
config/endpoints.json - ตรวจสอบ JSON format
- รีสตาร์ทแอพพลิเคชัน
- ตรวจสอบ logs เพื่อยืนยันการทำงาน
- ทดสอบการเชื่อมต่อกับ API
- ตรวจสอบ response time
- ยืนยัน schema validation
- ตรวจสอบ logs