Skip to content

API Test Guide

หน้านี้เป็นคู่มือเปิดดูเร็วสำหรับทดสอบ API ระหว่างอ่านหนังสือ

เหมาะกับ endpoint แบบ GET ที่ไม่ต้องส่ง body

http://localhost:8080/hello
http://localhost:8080/health

เหมาะกับ endpoint ที่ต้องกำหนด method, header, body หรือ token

ตัวอย่าง POST /api/v1/auth/login

{
"email": "john@example.com",
"password": "password123"
}

Header:

Content-Type: application/json
Terminal window
curl http://localhost:8080/health

POST JSON:

Terminal window
curl -X POST http://localhost:8080/api/v1/auth/login `
-H "Content-Type: application/json" `
-d "{\"email\":\"john@example.com\",\"password\":\"password123\"}"

ทดสอบ endpoint ที่ต้องใช้ JWT

Section titled “ทดสอบ endpoint ที่ต้องใช้ JWT”
Authorization: Bearer <token>

ใน Postman ให้ใส่ header:

Key: Authorization
Value: Bearer {{token}}

Checklist เวลา API ไม่ทำงาน

Section titled “Checklist เวลา API ไม่ทำงาน”
  1. Application รันอยู่หรือไม่
  2. Port ถูกต้องหรือไม่
  3. Path ถูกต้องหรือไม่
  4. HTTP method ถูกต้องหรือไม่
  5. Request body เป็น JSON ถูกต้องหรือไม่
  6. Header Content-Type ถูกต้องหรือไม่
  7. ถ้าเป็น protected endpoint ใส่ token แล้วหรือยัง