API Reference
API Reference
ภาพรวมการใช้งาน API รวมถึง Base URL, Authentication และ format ของ Response
Base URL
https://api.example.com/v1
Authentication
ทุก request ต้องส่ง Bearer Token ใน Header:
Authorization: Bearer <your_token>
ขอ Token
POST /auth/token
// Request Body
{
"client_id": "string",
"client_secret": "string"
}
// Response 200
{
"access_token": "eyJhbGci...",
"token_type": "Bearer",
"expires_in": 3600
}
Sequence: Authentication Flow
sequenceDiagram
participant Client
participant API
Client->>API: POST /auth/token { client_id, client_secret }
alt Valid credentials
API-->>Client: 200 OK { access_token, expires_in }
else Invalid credentials
API-->>Client: 401 Unauthorized { error: "invalid_credentials" }
end
Client->>API: GET /resource (Authorization: Bearer <token>)
alt Token valid
API-->>Client: 200 OK { data }
else Token expired
API-->>Client: 401 Unauthorized { error: "token_expired" }
end
Response Format
ทุก response ใช้ format เดียวกัน:
// Success
{
"success": true,
"data": { ... }
}
// Error
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "คำอธิบาย error"
}
}
HTTP Status Codes
| Code | ความหมาย |
|---|---|
200 |
OK - สำเร็จ |
201 |
Created - สร้างข้อมูลสำเร็จ |
400 |
Bad Request - Request ไม่ถูกต้อง |
401 |
Unauthorized - ไม่มีสิทธิ์หรือ Token หมดอายุ |
404 |
Not Found - ไม่พบข้อมูล |
500 |
Internal Server Error |