- การทดสอบ gRPC, GraphQL และ MCP ด้วย Postman
- Part 1: การทดสอบ GraphQL ด้วย Postman
- Part 2: การทดสอบ gRPC ด้วย Postman
- Part 3: การทดสอบ MCP ด้วย Postman
- Part 4: Authentication
- Part 5: การจัด Test Case
- Part 6: การจัด Collection
- Part 7: Environment Variables
- Part 8: Automation และ CI/CD
- Part 9: สิ่งที่ควรทดสอบ
- Part 10: เปรียบเทียบการทดสอบ
- Part 11: แนวทางสำหรับ Software Tester
- สรุป
#การทดสอบ gRPC, GraphQL และ MCP ด้วย Postman
Postman ไม่ได้จำกัดอยู่เฉพาะการทดสอบ REST API เท่านั้น ปัจจุบันสามารถใช้เป็น API Client สำหรับ protocol และรูปแบบการสื่อสารหลายประเภท เช่น GraphQL, gRPC และ Model Context Protocol (MCP) ได้ด้วย
บทความนี้อธิบายแนวทางใช้งาน Postman สำหรับการทดสอบทั้ง 3 รูปแบบ โดยเน้นมุมมองของนักพัฒนาและ Software Tester ตั้งแต่การสร้าง Request, การกำหนดข้อมูลนำเข้า, การตรวจสอบ Response, การเขียน Test Script ไปจนถึงแนวทางนำไปใช้ใน CI/CD
#1. ภาพรวม
ระบบสมัยใหม่อาจไม่ได้ใช้ REST API เพียงอย่างเดียว แต่เลือก protocol ตามลักษณะงาน
| เทคโนโลยี | ลักษณะเด่น | เหมาะกับ |
|---|---|---|
| REST | HTTP + JSON ใช้งานทั่วไป | Web API, Mobile API |
| GraphQL | Client เลือก field ที่ต้องการ | Frontend ที่ต้องการข้อมูลยืดหยุ่น |
| gRPC | RPC + Protocol Buffers | Microservices, Backend-to-Backend |
| MCP | Protocol สำหรับ AI Agent/LLM เชื่อมต่อ Tools และ Resources | AI Agent, LLM Tool Integration |
Postman มี client เฉพาะสำหรับ GraphQL และ gRPC และสามารถทำหน้าที่เป็น MCP client เพื่อเชื่อมต่อ MCP Server ได้
#Part 1: การทดสอบ GraphQL ด้วย Postman
#2. GraphQL คืออะไร
GraphQL เป็น Query Language สำหรับ API ที่เปิดให้ client ระบุข้อมูลที่ต้องการได้โดยตรง
ตัวอย่างเช่น REST อาจเรียก
GET /api/users/1
และ server ส่งข้อมูลทั้งหมดของผู้ใช้กลับมา
แต่ GraphQL สามารถกำหนดเฉพาะ field ที่ต้องการได้
query {
user(id: 1) {
id
name
email
}
}
ข้อดีคือช่วยลดปัญหา Over-fetching และ Under-fetching
#3. สร้าง GraphQL Request ใน Postman
เลือก
New
→ GraphQL
จากนั้นระบุ GraphQL Endpoint เช่น
http://localhost:4000/graphql
Postman มี GraphQL Client ที่สามารถใช้ schema introspection เพื่อแสดง field, query และ mutation ที่ API รองรับได้
#4. ตัวอย่าง GraphQL Query
สมมติระบบมี Query สำหรับค้นหาผู้ใช้
query GetUser {
user(id: 1) {
id
name
email
}
}
Response อาจเป็น
{
"data": {
"user": {
"id": "1",
"name": "John Doe",
"email": "john@example.com"
}
}
}
#5. GraphQL Variables
แทนที่จะ hard-code ค่าใน Query
query {
user(id: 1) {
id
name
}
}
สามารถใช้ตัวแปร
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
Variables
{
"id": "1"
}
วิธีนี้เหมาะกับการทดสอบแบบ Data-driven และช่วยให้ request ใช้ซ้ำได้ง่ายขึ้น
#6. ทดสอบ GraphQL Mutation
ตัวอย่าง Mutation สำหรับสร้าง User
mutation CreateUser($name: String!, $email: String!) {
createUser(name: $name, email: $email) {
id
name
email
}
}
Variables
{
"name": "Alice",
"email": "alice@example.com"
}
Response
{
"data": {
"createUser": {
"id": "10",
"name": "Alice",
"email": "alice@example.com"
}
}
}
#7. เขียน Test Script สำหรับ GraphQL
GraphQL Request รองรับ Script ก่อน Query และหลังได้รับ Response
ตัวอย่างตรวจสอบว่า Response มี data.user
pm.test("Should return user", function () {
const json = pm.response.json();
pm.expect(json.data).to.have.property("user");
pm.expect(json.data.user).to.have.property("id");
pm.expect(json.data.user).to.have.property("name");
});
ตรวจสอบ email
pm.test("Email should be correct", function () {
const json = pm.response.json();
pm.expect(json.data.user.email)
.to.eql("john@example.com");
});
#8. ตรวจสอบ GraphQL Error
GraphQL บางระบบอาจตอบ HTTP Status 200 แต่มี error อยู่ใน body
ตัวอย่าง
{
"errors": [
{
"message": "User not found"
}
]
}
ดังนั้นไม่ควรตรวจสอบเฉพาะ HTTP Status
pm.test("GraphQL should not contain errors", function () {
const json = pm.response.json();
pm.expect(json.errors).to.be.undefined;
});
หรือกรณี Negative Test
pm.test("Should return GraphQL error", function () {
const json = pm.response.json();
pm.expect(json.errors).to.be.an("array");
pm.expect(json.errors.length).to.be.greaterThan(0);
});
#Part 2: การทดสอบ gRPC ด้วย Postman
#9. gRPC คืออะไร
gRPC เป็น RPC Framework ที่นิยมใช้ในการสื่อสารระหว่าง service โดยเฉพาะระบบ Microservices
โดยทั่วไป gRPC ใช้
HTTP/2
+
Protocol Buffers
ในการสื่อสาร
ตัวอย่างไฟล์ .proto
syntax = "proto3";
package user;
service UserService {
rpc GetUser (GetUserRequest)
returns (UserResponse);
}
message GetUserRequest {
int32 id = 1;
}
message UserResponse {
int32 id = 1;
string name = 2;
string email = 3;
}
#10. สร้าง gRPC Request ใน Postman
เลือก
New
→ gRPC
ระบุ Server URL
localhost:50051
จากนั้นนำเข้าไฟล์
user.proto
Postman จะอ่าน Service Definition และแสดง Service/Method ที่สามารถเรียกใช้งานได้
ตัวอย่าง
UserService
├─ GetUser
├─ CreateUser
├─ UpdateUser
└─ DeleteUser
#11. ทดสอบ Unary gRPC
เลือก Method
UserService/GetUser
Message
{
"id": 1
}
กด
Invoke
Response
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
#12. gRPC Metadata
gRPC ใช้ Metadata คล้าย HTTP Header
ตัวอย่าง
authorization
Bearer {{token}}
หรือ
x-api-key
{{api_key}}
เหมาะสำหรับ
- Authentication
- Authorization
- Trace ID
- Correlation ID
- Service Metadata
#13. ประเภทของ gRPC Method
gRPC รองรับ communication pattern หลัก 4 แบบ
#Unary
Client → Request
Server → Response
ตัวอย่าง
GetUser
#Server Streaming
Client → Request
Server → Response
Response
Response
เช่น
ListNotifications
#Client Streaming
Client → Request
Request
Request
Server → Response
เช่นการ upload ข้อมูลหลาย message
#Bidirectional Streaming
Client ↔ Server
ทั้งสองฝั่งสามารถส่ง message ต่อเนื่องได้
Postman สามารถช่วยทดสอบ gRPC ทั้ง unary และ streaming methods ได้
#14. เขียน Test Script สำหรับ gRPC
gRPC Request ใน Postman มีจุดสำหรับ Script หลัก ได้แก่
Before invoke
On message
After response
#ตรวจสอบ Message
pm.test("User ID should exist", function () {
const response = pm.response.json();
pm.expect(response.id).to.exist;
});
#ตรวจสอบชื่อ
pm.test("Name should be John Doe", function () {
const response = pm.response.json();
pm.expect(response.name).to.eql("John Doe");
});
สำหรับ Streaming สามารถใช้ On message เพื่อทดสอบทุก message ที่ส่งกลับมาจาก server
#Part 3: การทดสอบ MCP ด้วย Postman
#15. MCP คืออะไร
Model Context Protocol (MCP) เป็น protocol สำหรับเชื่อม AI Model หรือ AI Agent เข้ากับระบบภายนอก เช่น
Database
File System
Search API
GitHub
Google Drive
Business APIs
Internal Services
โครงสร้างโดยทั่วไป
AI Application
│
▼
MCP Client
│
▼
MCP Server
│
├── Tools
├── Resources
└── Prompts
Postman สามารถทำหน้าที่เป็น MCP Client เพื่อใช้ทดลอง ทดสอบ และประเมิน MCP Server ได้
#16. MCP Capability หลัก
#Tools
Tool คือ action ที่ MCP Server เปิดให้ client หรือ AI Agent เรียกใช้งาน
ตัวอย่าง
search_product
create_order
get_weather
query_database
ตัวอย่าง arguments
{
"city": "Bangkok"
}
#Resources
Resource คือข้อมูลที่ MCP Server เปิดให้อ่าน
ตัวอย่าง
file://docs/manual.md
database://customers/1001
config://application
#Prompts
Prompt คือ template ที่ MCP Server เตรียมไว้ให้ AI ใช้งาน
ตัวอย่าง
summarize_document
generate_report
analyze_customer
#17. Transport ของ MCP
Postman รองรับ transport ที่สำคัญ เช่น
STDIO
และ
Streamable HTTP
ตัวอย่าง Streamable HTTP MCP Server
http://localhost:3000/mcp
ในกรณี Streamable HTTP, Postman สามารถ negotiate protocol version กับ server ขณะเชื่อมต่อได้
#18. สร้าง MCP Request ใน Postman
สร้าง Request ใหม่แล้วเลือก
MCP
จากนั้นเลือก transport
STDIO
หรือ
Streamable HTTP
กรณี HTTP ระบุ endpoint
http://localhost:3000/mcp
จากนั้นเลือก
Load Capabilities
Postman จะแสดง capability ที่ MCP Server เปิดให้ใช้งาน เช่น
Tools
Resources
Prompts
#19. ทดสอบ MCP Tool
สมมติ MCP Server มี Tool
get_weather
Input Schema
{
"city": "string"
}
Arguments
{
"city": "Bangkok"
}
กด
Run
Response ตัวอย่าง
{
"temperature": 32,
"condition": "Cloudy"
}
สิ่งที่ควรตรวจสอบ ได้แก่
Tool ถูกค้นพบหรือไม่
Input Schema ถูกต้องหรือไม่
รับ Required Argument ครบหรือไม่
Output ถูกต้องหรือไม่
Error Handling ทำงานหรือไม่
#20. Negative Test สำหรับ MCP
ควรทดสอบกรณีผิดพลาดด้วย
#ไม่ส่ง Required Field
{}
ระบบควรปฏิเสธ request หรือคืน validation error
#ส่งชนิดข้อมูลผิด
{
"city": 123
}
ถ้า schema ระบุ city เป็น string ควรเกิด error
#Tool ไม่มีอยู่
เช่นเรียก
unknown_tool
ระบบควรส่ง error ที่ชัดเจน
#Authentication ไม่ถูกต้อง
ตัวอย่าง
Invalid API Key
Expired Token
Insufficient Permission
#Part 4: Authentication
#21. GraphQL Authentication
ตัวอย่าง Bearer Token
Authorization
Bearer {{token}}
สามารถเก็บ token ใน Postman Environment
{{token}}
#22. gRPC Authentication
สามารถใส่ใน Metadata
authorization
Bearer {{token}}
#23. MCP Authentication
สำหรับ Streamable HTTP สามารถกำหนด Authorization ของ Request ได้ เช่น
Bearer Token
API Key
OAuth 2.x
ส่วน STDIO มักกำหนด secret หรือ credential ผ่าน environment variables ตามรูปแบบของ MCP Server
ควรหลีกเลี่ยงการ hard-code token ลงใน request ที่แชร์กับทีม
#Part 5: การจัด Test Case
#24. ตัวอย่าง Test Matrix
| Test Case | GraphQL | gRPC | MCP |
|---|---|---|---|
| Positive Request | ✅ | ✅ | ✅ |
| Required Field | ✅ | ✅ | ✅ |
| Invalid Data Type | ✅ | ✅ | ✅ |
| Authentication | ✅ | ✅ | ✅ |
| Authorization | ✅ | ✅ | ✅ |
| Error Handling | ✅ | ✅ | ✅ |
| Schema Validation | ✅ | ✅ | ✅ |
| Performance | ✅ | ✅ | ✅ |
| Streaming | ❌ | ✅ | ✅/ขึ้นกับ server |
| Tool Discovery | ❌ | ❌ | ✅ |
#Part 6: การจัด Collection
#25. โครงสร้าง Collection ที่แนะนำ
API Testing
│
├── GraphQL
│ ├── Get User
│ ├── Create User
│ ├── Update User
│ ├── Invalid Input
│ └── Authorization
│
├── gRPC
│ ├── GetUser
│ ├── CreateUser
│ ├── ServerStreaming
│ └── Authentication
│
└── MCP
├── Tool - get_weather
├── Tool - search_product
├── Resource
├── Prompt
└── Invalid Input
การแยกตาม protocol ทำให้อ่านง่ายและสะดวกต่อการ debug
#Part 7: Environment Variables
#26. ตัวอย่าง Environment
graphql_url
grpc_url
mcp_url
token
api_key
ตัวอย่าง
graphql_url = http://localhost:4000/graphql
grpc_url = localhost:50051
mcp_url = http://localhost:3000/mcp
จากนั้นเรียกใช้งานเป็น
{{graphql_url}}
{{grpc_url}}
{{mcp_url}}
#Part 8: Automation และ CI/CD
#27. GraphQL และ gRPC Collection Runs
Postman สามารถใช้ Collection Runner สำหรับ automated functional testing ของ HTTP, GraphQL และ gRPC requests ได้
แนวทางทั่วไป
Developer Push Code
│
▼
CI Pipeline
│
▼
Postman CLI
│
▼
Run Collection
│
▼
GraphQL / gRPC API
│
▼
Test Result
ตัวอย่าง pipeline
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Postman CLI
run: |
curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
- name: Run API Tests
run: |
postman collection run "$POSTMAN_COLLECTION_ID" \
-e "$POSTMAN_ENVIRONMENT_ID"
หมายเหตุ: รูปแบบคำสั่งและ authentication ของ Postman CLI ควรตรวจสอบกับเอกสารเวอร์ชันล่าสุดก่อนใช้งานจริง
สำหรับ MCP ปัจจุบัน Postman เหมาะอย่างยิ่งกับการทำ interactive testing และ evaluation ของ server capabilities เช่น Tools, Resources และ Prompts ขณะที่ workflow automation ควรออกแบบให้สอดคล้องกับความสามารถของ Postman เวอร์ชันที่ใช้งานและ MCP Server ของโครงการ
#Part 9: สิ่งที่ควรทดสอบ
#28. GraphQL Checklist
□ Query ทำงานถูกต้อง
□ Mutation ทำงานถูกต้อง
□ Variable ถูกต้อง
□ Required Field
□ Invalid Type
□ GraphQL errors
□ Authentication
□ Authorization
□ Schema
□ Response Time
#29. gRPC Checklist
□ Protobuf Schema
□ Service Discovery
□ Unary RPC
□ Client Streaming
□ Server Streaming
□ Bidirectional Streaming
□ Metadata
□ Authentication
□ Status/Error
□ Response Message
#30. MCP Checklist
□ Connection
□ Protocol Negotiation
□ Capability Discovery
□ Tool Discovery
□ Tool Input Schema
□ Tool Output
□ Resource Access
□ Prompt Access
□ Authentication
□ Invalid Arguments
□ Unknown Tool
□ Error Handling
□ Permission Boundary
#Part 10: เปรียบเทียบการทดสอบ
#31. GraphQL vs gRPC vs MCP
| Feature | GraphQL | gRPC | MCP |
|---|---|---|---|
| รูปแบบหลัก | Query Language | RPC | AI/Agent Protocol |
| Schema | GraphQL Schema | Protocol Buffers | Capability/Input Schema |
| Transport | HTTP | HTTP/2 | STDIO / Streamable HTTP |
| Client | Frontend/API Client | Service | AI Agent/MCP Client |
| Response | JSON | Protobuf-based message | Structured content/results |
| Streaming | Subscription/implementation dependent | Native | Transport/capability dependent |
| Postman Client | ✅ | ✅ | ✅ |
| Script-based API Tests | ✅ | ✅ | แตกต่างตาม MCP workflow |
| เหมาะกับ | Web API | Microservices | AI Agent Integration |
#Part 11: แนวทางสำหรับ Software Tester
#32. อย่าทดสอบเฉพาะ Happy Path
ตัวอย่าง
Valid Request
ควรเพิ่ม
Missing Field
Invalid Type
Invalid Token
Expired Token
Unauthorized Access
Resource Not Found
Malformed Payload
Timeout
Server Error
#33. ตรวจสอบ Contract
GraphQL
Schema
Query
Mutation
Field Type
Nullability
gRPC
.proto
Service
RPC Method
Message Type
Field Number
MCP
Capabilities
Tool Input Schema
Resource
Prompt
Authentication
Protocol Version
#34. แยก Functional Test กับ Performance Test
Postman เหมาะมากกับ
Functional Testing
Contract Testing
Integration Testing
Exploratory API Testing
แต่ถ้าต้องการ load สูง เช่น
1,000
10,000
100,000
concurrent requests ควรใช้เครื่องมือ Performance Testing โดยเฉพาะ เช่น
k6
JMeter
Gatling
Locust
#สรุป
Postman สามารถใช้เป็นศูนย์กลางสำหรับทดสอบ interface สมัยใหม่ได้มากกว่า REST API
Postman
│
├── HTTP / REST
├── GraphQL
├── gRPC
└── MCP
สำหรับ GraphQL จุดสำคัญคือการทดสอบ Query, Mutation, Variables, Schema และ GraphQL Error
สำหรับ gRPC ควรตรวจสอบ Service Definition, RPC Method, Metadata, Message และ Streaming Behavior
สำหรับ MCP ควรเน้น Connection, Capability Discovery, Tools, Resources, Prompts, Input Schema, Authentication และ Error Handling
หากจัด request อย่างเป็นระบบใน Postman Collections และใช้ Environment Variables ร่วมกับ Test Scripts จะช่วยให้ทีมสามารถทำ API testing ได้ทั้งแบบ manual, reusable และ automated ใน workflow เดียวกัน
#แหล่งข้อมูลอ้างอิง
-
Postman Docs — GraphQL Client
https://learning.postman.com/docs/use/send-requests/protocols/graphql/graphql-client-interface/ -
Postman Docs — GraphQL over HTTP
https://learning.postman.com/docs/use/send-requests/protocols/graphql/graphql-http/ -
Postman Docs — gRPC Client
https://learning.postman.com/docs/use/send-requests/protocols/grpc/grpc-client-overview/ -
Postman Docs — gRPC Request Interface
https://learning.postman.com/docs/use/send-requests/protocols/grpc/grpc-request-interface/ -
Postman Docs — MCP Requests
https://learning.postman.com/docs/use/send-requests/protocols/mcp-requests/overview/ -
Postman Docs — Create an MCP Request
https://learning.postman.com/docs/use/send-requests/protocols/mcp-requests/create/ -
Postman Docs — Interact with MCP Server
https://learning.postman.com/docs/use/send-requests/protocols/mcp-requests/interact/ -
Postman Docs — Collection Runner
https://learning.postman.com/docs/tests-and-scripts/running-collections/intro-to-collection-runs/