This guide shows you how to import and test the entire API using Postman.
Download from: https://www.postman.com/downloads/
# Install dependencies
npm install
# Set up database
npm run db:migrate
npm run db:seed
# Start server
npm run devServer should start at: http://localhost:3000
- Open Postman
- Click Import in the top left
- Drag and drop
postman-collection.jsonfile - Click Import
You should see "Reservation System API" in your collections.
- Click the gear icon (top right) → "Manage Environments"
- Click Import
- Select
postman-environment.json - Click Import
In the environment dropdown (top right), select Reservation API - Local.
The collection is organized into folders:
- Health Check - Verify server is running
- Readiness Check - Check dependencies
- List All Items - Get all items with stock
- Get Single Item - Get specific item details
- Reserve Item - Create new reservation
- Confirm Reservation - Confirm reservation
- Cancel Reservation - Cancel reservation
- Get Reservation - Get reservation details
- List User's Reservations - Get all user's reservations
- Expire Old Reservations - Manual expiration job
Tests for each feature:
- Validation tests (missing fields, invalid values)
- Error tests (404, 409, etc.)
- Idempotency tests
- Rate limiting test
- Open 1. Health & Setup folder
- Click Health Check
- Click Send
Expected Response (200):
{
"ok": true,
"data": {
"status": "healthy"
}
}- Open 2. Items folder
- Click List All Items
- Click Send
Expected Response (200):
{
"ok": true,
"data": [
{
"id": "item_1",
"name": "Wireless Mouse",
"availableQty": 5
}
]
}- Open 5. Feature Tests folder
- Click Validation - Missing Field
- Click Send
Expected Response (400):
{
"ok": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"field": "userId",
"message": "User ID is required"
}
]
}
}- Click Validation - Invalid Quantity
- Click Send
Expected Response (400):
{
"ok": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"field": "qty",
"message": "Quantity must be at least 1"
}
]
}
}- Click Validation - Invalid ID Format
- Click Send
Expected Response (400):
{
"ok": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid user ID format"
}
}- Open 3. Reservations folder
- Click Reserve Item
- Click Send
Expected Response (201):
{
"ok": true,
"data": {
"id": "res_abc123...",
"userId": "user_1",
"itemId": "item_1",
"qty": 1,
"status": "reserved",
"expiresAt": 1706720400000
}
}Important: The reservation_id is automatically saved to your environment!
- Click Get Reservation
- Click Send
Uses the reservation_id saved from Feature 4.
Expected Response (200):
{
"ok": true,
"data": {
"id": "res_abc123...",
"status": "reserved"
}
}- Click Confirm Reservation
- Click Send
Expected Response (200):
{
"ok": true,
"data": {
"status": "confirmed"
}
}- Open 5. Feature Tests folder
- Click Idempotency Test 1
- Note the timestamp in the Idempotency-Key header
- Click Send
Save the reservation_id from response.
- Click Idempotency Test 2
- IMPORTANT: Edit the Idempotency-Key to use the SAME timestamp as Test 1
- Click Send
Expected: Returns the SAME reservation_id as Test 1!
- Click Rate Limit Test
- Click the ... menu → "Run collection"
- Select only "Rate Limit Test"
- Set iterations to 25
- Click Run
Expected:
- Requests 1-20: ✅ Success (201)
- Requests 21-25: ❌ Rate Limited (429)
Rate Limited Response (429):
{
"ok": false,
"error": {
"code": "RATE_LIMITED",
"message": "Too many requests",
"details": {
"retryAfter": 5
}
}
}- Click Conflict - Out of Stock
- Click Send
Expected Response (409):
{
"ok": false,
"error": {
"code": "OUT_OF_STOCK",
"message": "Not enough stock available",
"details": {
"itemId": "item_1",
"requested": 9999,
"available": 5
}
}
}- Click Not Found - Invalid Item
- Click Send
Expected Response (404):
{
"ok": false,
"error": {
"code": "ITEM_NOT_FOUND",
"message": "Item not found"
}
}Run through this full workflow:
- List Items - See what's available
- Reserve Item - Create a reservation (saves
reservation_id) - Get Reservation - Check the reservation details
- Confirm Reservation - Confirm the reservation
- Try to Cancel - Should fail (already confirmed)
The environment uses these variables:
| Variable | Value | Purpose |
|---|---|---|
base_url |
http://localhost:3000 |
API base URL |
user_id |
user_1 |
Test user ID |
item_id |
item_1 |
Test item ID |
reservation_id |
Auto-saved | Latest reservation ID |
- Click the environment dropdown (top right)
- Click Edit next to "Reservation API - Local"
- Change
user_idtouser_2 - Click Save
- Click Send on any request
- Edit environment
- Change
item_idtoitem_2 - Save
- Click ... on "Reservation System API" collection
- Select Run collection
- Choose which requests to run (or "Run all")
- Set iteration count (usually 1)
- Click Run
- Expand 5. Feature Tests folder
- Click ... on the folder
- Select Run collection
- All feature tests will run
The collection includes test scripts that:
- ✅ Auto-save
reservation_idafter successful reservation - ✅ Verify response status codes
- ✅ Check response format
View test results:
- Click the Test Results tab
- See which tests passed/failed
The idempotency test uses {{$timestamp}} which generates a timestamp.
To make it work:
- Run Idempotency Test 1
- Quickly copy the Idempotency-Key from the headers
- Paste it into Idempotency Test 2
- Run Test 2 within a few seconds
Or edit the keys manually:
- Test 1:
test-idempotency-123 - Test 2:
test-idempotency-123(same!)
- Use Collection Runner for rate limit test
- Don't wait too long between requests (10 second window)
- Check response headers for
X-RateLimit-Remaining
While testing, watch the server logs:
npm run devYou'll see structured logs for each request with:
- Request ID
- Method and path
- Status code
- Duration
Problem: Server not running
Solution:
npm run devProblem: Multiple server instances running
Solution:
# Kill all node processes
pkill -9 node
# Restart
npm run devProblem: Request failed or didn't return 201
Solution:
- Check response body
- Fix the error
- Try again
Problem: Requests not hitting rate limit
Solution:
- Make sure you're using the same IP
- Check
X-RateLimit-Limitheader in response - Don't wait too long between requests (10 second window)
| Test | Validates | Expected Status |
|---|---|---|
| Health Check | Server running | 200 |
| List Items | Data retrieval | 200 |
| Reserve Item | Create resource | 201 |
| Validation - Missing Field | Input validation | 400 |
| Validation - Invalid Qty | Input validation | 400 |
| Not Found | Error handling | 404 |
| Out of Stock | Business logic | 409 |
| Idempotency Test 1 | First request | 201 |
| Idempotency Test 2 | Duplicate key | 201 (same ID) |
| Rate Limit (1-20) | Under limit | 201 |
| Rate Limit (21+) | Over limit | 429 |
You've successfully tested everything when:
✅ Health check returns 200 ✅ Can list items ✅ Can reserve item (reservation_id saved) ✅ Validation errors return 400 ✅ Not found returns 404 ✅ Out of stock returns 409 ✅ Idempotency returns same ID ✅ Rate limited after 20 requests ✅ Can confirm reservation ✅ Can get reservation details
💡 Tip: Use Postman's "History" tab to see all your requests and their responses!