Appearance
03.06 Response Format
📌 At a Glance
| รายการ | รายละเอียด |
|---|---|
| Topic | Response Format |
| Difficulty | ⭐ Beginner |
| Reading Time | 6 นาที |
| Target | Developer |
🎯 Learning Objectives
หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ
- เข้าใจโครงสร้าง Response ของ SISAHYGO API
- แยก Success และ Error Response ได้
- อ่านข้อมูลจาก Response ได้อย่างถูกต้อง
- นำ Response ไปใช้งานใน Client System ได้
Overview
SISAHYGO API ใช้มาตรฐาน JSON Response เดียวกันสำหรับทุก Endpoint เพื่อให้ Client System สามารถพัฒนาโค้ดได้ง่าย และลดความซับซ้อนในการจัดการผลลัพธ์
ทุก Response ประกอบด้วย
- Status
- Message
- Data
- Metadata
ไม่ว่า Endpoint ใดก็จะใช้รูปแบบเดียวกัน
Figure 3-6 Standard Response Format
(แทรกรูป Figure 3-6 : Standard Response Format)

Figure 3-6 แสดงองค์ประกอบของ JSON Response มาตรฐานของ SISAHYGO API ซึ่งประกอบด้วย Success Flag, Response Code, Message, Data และ Metadata
Standard Success Response
json
{
"success": true,
"code": "200",
"message": "Success",
"data": {
"items": [
...
]
},
"timestamp": "2026-07-02T10:15:30+07:00",
"version": "1.1"
}Response Fields
| Field | Type | Description |
|---|---|---|
| success | Boolean | ผลการทำงานของ API |
| code | String | Response Code |
| message | String | ข้อความอธิบาย |
| data | Object | ข้อมูลที่ส่งกลับ |
| timestamp | DateTime | เวลาที่ระบบตอบกลับ |
| version | String | API Version |
Success Response
เมื่อ Request สำเร็จ
HTTP 200 OKพร้อมข้อมูลใน data
Error Response
หากเกิดข้อผิดพลาด
json
{
"success": false,
"code": "AUTH001",
"message": "Invalid API Key",
"data": null,
"timestamp": "2026-07-02T10:15:30+07:00",
"version": "1.1"
}รายละเอียดของ Error Code จะอธิบายใน Section 3.9
Key Points
| Item | Value |
|---|---|
| Format | JSON |
| Encoding | UTF-8 |
| Success Flag | Boolean |
| Timestamp | ISO 8601 |
| Version | API Version |
Implementation Notes
- ตรวจสอบค่า
successก่อนใช้งานข้อมูล - อ่านข้อมูลจาก
data - ไม่ควรตรวจสอบจาก
message - ใช้
codeสำหรับจัดการ Error ภายในระบบ
Best Practices
- ใช้
successเป็นเงื่อนไขหลักในการตรวจสอบผลลัพธ์ - บันทึก
codeและtimestampเมื่อต้องการวิเคราะห์ปัญหา - อย่าใช้ข้อความ
messageใน Business Logic - รองรับ Field ใหม่ที่อาจเพิ่มในอนาคต โดยไม่ทำให้ Client พัง
Summary
SISAHYGO API ใช้โครงสร้าง JSON Response เดียวกันทุก Endpoint ทำให้การพัฒนา Client System มีความง่าย สม่ำเสมอ และสามารถจัดการ Success และ Error ได้ด้วยโค้ดชุดเดียว
Next Step
➡️ 03.07 HTTP Status Codes
