Skip to content

04.05 Using Postman ​


📌 At a Glance ​

รายการรายละเอียด
TopicUsing Postman
Difficulty⭐ Beginner
Reading Time8 นาที
TargetDeveloper

🎯 Learning Objectives ​

หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ

  • สร้าง Postman Environment
  • กำหนดค่า Environment Variables
  • ทดลองเรียก SISAHYGO API ผ่าน Postman
  • ตรวจสอบ Request และ Response ได้

Overview ​

Postman เป็นเครื่องมือที่แนะนำสำหรับการทดสอบ SISAHYGO API เนื่องจากสามารถจัดการ Environment Variables, HTTP Headers และ JSON Response ได้สะดวก

แนะนำให้ทดสอบทุก Endpoint ผ่าน Postman ก่อนเริ่มพัฒนาในภาษาโปรแกรมจริง


Figure 4-5 Using Postman ​

Figure 4-5

Figure 4-5 แสดงขั้นตอนการใช้งาน Postman ตั้งแต่การสร้าง Environment การกำหนดตัวแปร การส่ง Request และการตรวจสอบ JSON Response


Step 1 : Create Environment ​

สร้าง Environment ใหม่

SISAHYGO Production

เพิ่มตัวแปรดังนี้

VariableValue
base_urlhttps://app.sisahygo.online/api/v1
api_keysk_live_xxxxxxxxxxxxxxxxx

Step 2 : Create Request ​

Method

http
GET

URL

text
{{base_url}}/products

Headers

http
X-API-Key: {{api_key}}

Accept: application/json

Step 3 : Send Request ​

กดปุ่ม Send

หากการเชื่อมต่อสำเร็จ จะได้รับ HTTP 200 OK พร้อมข้อมูลสินค้าในรูปแบบ JSON


Step 4 : Verify Response ​

ตรวจสอบ

  • HTTP Status = 200
  • success = true
  • code = 200
  • data มีข้อมูล
  • version = 1.1

Recommended Collection ​

แนะนำให้สร้าง Collection ดังนี้

text
SISAHYGO API V1.1

├── Master Data
│   ├── GET Products
│   └── GET Receivers
│
├── Transaction
│   └── POST Order Checkings
│
└── Tracking
    ├── GET Shipments
    └── GET Order Rejections

Environment Variables ​

text
base_url

api_key

ใช้ Environment Variables แทนการ Hardcode URL หรือ API Key


Key Points ​

ItemRecommendation
Environmentใช้ตัวแปรแทนค่าคงที่
API KeyEnvironment Variable
Base URLEnvironment Variable
Collectionแยกตามหมวด API

Implementation Notes ​

  • ไม่บันทึก API Key ลงใน Collection ที่แชร์
  • Export Environment โดยลบ API Key ก่อน
  • ใช้ Collection เดียวกันทั้งทีมพัฒนา
  • ตั้งชื่อ Request ให้ตรงกับชื่อ Endpoint

Best Practices ​

  • แยก Collection ตามหมวด API
  • ใช้ Environment Variables ทุกครั้ง
  • บันทึกตัวอย่าง Response เพื่อใช้ทดสอบ
  • ตรวจสอบ HTTP Status และ JSON Response ทุก Request

Summary ​

Postman เป็นเครื่องมือที่ช่วยให้ Developer สามารถทดสอบ SISAHYGO API ได้อย่างรวดเร็ว ลดเวลาในการตรวจสอบปัญหา และช่วยให้ทีมพัฒนาใช้มาตรฐานเดียวกัน


Next Step ​

➡️ 04.06 Testing Checklist

SISAHYGO API Integration Guide