API Test Guide
เป้าหมาย
Section titled “เป้าหมาย”หน้านี้เป็นคู่มือเปิดดูเร็วสำหรับทดสอบ API ระหว่างอ่านหนังสือ
ทดสอบด้วย browser
Section titled “ทดสอบด้วย browser”เหมาะกับ endpoint แบบ GET ที่ไม่ต้องส่ง body
http://localhost:8080/hellohttp://localhost:8080/healthทดสอบด้วย Postman
Section titled “ทดสอบด้วย Postman”เหมาะกับ endpoint ที่ต้องกำหนด method, header, body หรือ token
ตัวอย่าง POST /api/v1/auth/login
{ "email": "john@example.com", "password": "password123"}Header:
Content-Type: application/jsonทดสอบด้วย curl
Section titled “ทดสอบด้วย curl”curl http://localhost:8080/healthPOST JSON:
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: AuthorizationValue: Bearer {{token}}Checklist เวลา API ไม่ทำงาน
Section titled “Checklist เวลา API ไม่ทำงาน”- Application รันอยู่หรือไม่
- Port ถูกต้องหรือไม่
- Path ถูกต้องหรือไม่
- HTTP method ถูกต้องหรือไม่
- Request body เป็น JSON ถูกต้องหรือไม่
- Header
Content-Typeถูกต้องหรือไม่ - ถ้าเป็น protected endpoint ใส่ token แล้วหรือยัง