Postman Testing Guide
This guide provides complete examples for testing Kairos Gateway using Postman. It covers testing public routes, JWT-protected routes, and the configuration management API.
๐ Quick Setup
-
Start Kairos Gateway:
The server runs onhttp://localhost:5900by default. -
Current Configuration: The examples below assume you are using the default
config.jsonprovided in the repository.
๐ Postman Collection Examples
1. Public Route - Cat Images (No Auth) ๐ฑ
Request Details: - Method: GET - URL: http://localhost:5900/cats/200 - Headers: None required
Expected Response: - Status: 200 OK - Content: Cat image (HTTP status cat) - This route forwards to https://http.cat/200
Postman Setup:
2. Protected Route - Cat Images (JWT Required) ๐๐ฑ
Request Details: - Method: GET - URL: http://localhost:5900/protected/cats/404 - Headers: - Authorization: Bearer YOUR_JWT_TOKEN
Expected Response: - Without token: 401 Unauthorized - With valid token: 200 OK + cat image
Postman Setup:
GET http://localhost:5900/protected/cats/404
Headers:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTksImlzcyI6ImthaXJvcy1nYXRld2F5IiwiYXVkIjoiYXBpLWNsaWVudHMifQ.rJxLfHn8h6lUoFJmKrWOZfP5HnPnEKfP0OGNjEhTJfA
3. Local Service Route - Identity Registration ๐ง
Request Details: - Method: POST or GET - URL: http://localhost:5900/api/identity/register/v3 - Headers: Content-Type: application/json - Body (for POST):
Expected Response: - Depends on your local service running on localhost:3000 - If service is down: Gateway will return appropriate error
Postman Setup:
POST http://localhost:5900/api/identity/register/v3
Headers:
Content-Type: application/json
Body (raw JSON):
{
"username": "testuser",
"email": "test@example.com",
"password": "securepassword"
}
4. External Route - Google Homepage ๐
Request Details: - Method: GET - URL: http://localhost:5900/identity/register/v2 - Headers: None required
Expected Response: - Status: 200 OK - Content: Google homepage HTML - This route forwards to https://google.com/
Postman Setup:
๐ JWT Token Generation
Since the protected routes require JWT authentication, you need a valid token. Here are options:
Option 1: Use Test Token (Valid until 2033)
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTksImlzcyI6ImthaXJvcy1nYXRld2F5IiwiYXVkIjoiYXBpLWNsaWVudHMifQ.rJxLfHn8h6lUoFJmKrWOZfP5HnPnEKfP0OGNjEhTJfA
Option 2: Generate Your Own Token
Use jwt.io with these settings:
Header:
Payload:
{
"sub": "1234567890",
"iat": 1516239022,
"exp": 9999999999,
"iss": "kairos-gateway",
"aud": "api-clients"
}
Secret: your-super-secure-jwt-secret-key-must-be-at-least-32-characters-long
Option 3: Create Token with curl
๐ Testing Rate Limiting
The gateway has rate limiting enabled. To test it:
-
Send multiple rapid requests:
-
Expected behavior:
- First requests:
200 OK - After limit:
429 Too Many Requests
๐ Health Check Endpoints
Health Check:
Expected:200 OK with status information Metrics (Prometheus format):
Expected:200 OK with Prometheus metrics ๐งช Complete Postman Collection JSON
You can import this collection directly into Postman:
{
"info": {
"name": "Kairos-rs API Gateway Tests",
"description": "Test collection for Kairos-rs gateway functionality",
"version": "1.0.0"
},
"item": [
{
"name": "Public Cat Image",
"request": {
"method": "GET",
"url": "http://localhost:5900/cats/200",
"description": "Test public route without authentication"
}
},
{
"name": "Protected Cat Image",
"request": {
"method": "GET",
"url": "http://localhost:5900/protected/cats/404",
"header": [
{
"key": "Authorization",
"value": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTksImlzcyI6ImthaXJvcy1nYXRld2F5IiwiYXVkIjoiYXBpLWNsaWVudHMifQ.rJxLfHn8h6lUoFJmKrWOZfP5HnPnEKfP0OGNjEhTJfA"
}
],
"description": "Test protected route with JWT authentication"
}
},
{
"name": "Identity Registration POST",
"request": {
"method": "POST",
"url": "http://localhost:5900/api/identity/register/v3",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"testuser\",\n \"email\": \"test@example.com\",\n \"password\": \"securepassword\"\n}"
},
"description": "Test local service route with POST data"
}
},
{
"name": "Google Homepage Route",
"request": {
"method": "GET",
"url": "http://localhost:5900/identity/register/v2",
"description": "Test external service routing to Google"
}
},
{
"name": "Health Check",
"request": {
"method": "GET",
"url": "http://localhost:5900/health",
"description": "Check gateway health status"
}
},
{
"name": "Metrics Endpoint",
"request": {
"method": "GET",
"url": "http://localhost:5900/metrics",
"description": "Get Prometheus metrics"
}
}
]
}
โก Advanced Testing Scenarios
1. Test Circuit Breaker
- Stop your local service on port 3000
- Make requests to
http://localhost:5900/api/identity/register/v3 - After several failures, circuit breaker should open
- Subsequent requests will fail fast
2. Test Rate Limiting
- Use Postman Runner or Newman to send rapid requests
- Monitor for
429 Too Many Requestsresponses - Check
/metricsendpoint for rate limit statistics
3. Test JWT Validation
- Try requests with no Authorization header
- Try with malformed JWT tokens
- Try with expired tokens
- Try with wrong secret signatures
๐จ Troubleshooting
Common Issues:
- Connection Refused:
- Make sure Kairos-rs is running:
cargo run -
Check it's listening on port 5900
-
JWT Authentication Fails:
- Verify token is properly formatted
- Check the secret matches configuration
-
Ensure required claims (sub, exp) are present
-
Route Not Found:
- Verify URL matches exactly the external_path in config
-
Check HTTP method is allowed in configuration
-
Local Service Errors:
- Make sure your local service is running on port 3000
- Check service is accessible directly
๐ฏ Expected Test Results
| Route | Status | Response |
|---|---|---|
/cats/200 | 200 OK | Cat image |
/protected/cats/404 (no auth) | 401 Unauthorized | Auth error |
/protected/cats/404 (with JWT) | 200 OK | Cat image |
/api/identity/register/v3 | Depends on local service | Service response |
/identity/register/v2 | 200 OK | Google homepage |
/health | 200 OK | Health status |
/metrics | 200 OK | Prometheus metrics |
Happy testing! ๐