Testing Your API
APSO provides multiple ways to test and explore your generated API. This guide covers Swagger UI, curl, and popular API clients.
Swagger UI
Every APSO server includes built-in Swagger documentation:
http://localhost:3001/api/docsFeatures
- Interactive API exploration
- Request builder with form fields
- Response visualization
- Authentication support
- Schema documentation
Authenticating in Swagger
- Click Authorize button
- Enter your Bearer token:
Bearer <your-token> - Click Authorize
- All requests will include your token
Using curl
Health Check
curl http://localhost:3001/healthGet All Records
curl -X GET http://localhost:3001/api/v1/projects \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json"Get Single Record
curl -X GET http://localhost:3001/api/v1/projects/<id> \
-H "Authorization: Bearer <token>"Create Record
curl -X POST http://localhost:3001/api/v1/projects \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "New Project",
"description": "Project description"
}'Update Record
curl -X PATCH http://localhost:3001/api/v1/projects/<id> \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Name"
}'Delete Record
curl -X DELETE http://localhost:3001/api/v1/projects/<id> \
-H "Authorization: Bearer <token>"Query Parameters
Pagination
# Get page 2 with 10 items per page
curl "http://localhost:3001/api/v1/projects?limit=10&offset=10" \
-H "Authorization: Bearer <token>"Filtering
# Filter by status
curl "http://localhost:3001/api/v1/projects?status=active" \
-H "Authorization: Bearer <token>"
# Multiple filters
curl "http://localhost:3001/api/v1/projects?status=active&priority=1" \
-H "Authorization: Bearer <token>"Sorting
# Sort by createdAt descending
curl "http://localhost:3001/api/v1/projects?sortBy=createdAt&sortOrder=desc" \
-H "Authorization: Bearer <token>"Including Relations
# Include related tasks
curl "http://localhost:3001/api/v1/projects?include=tasks" \
-H "Authorization: Bearer <token>"Postman
Import OpenAPI Spec
- Open Postman
- Click Import
- Enter:
http://localhost:3001/api/docs-json - Click Import
All endpoints are now available in Postman.
Set Up Environment
Create a Postman environment with:
| Variable | Value |
|---|---|
baseUrl | http://localhost:3001 |
token | <your-bearer-token> |
Request Examples
GET Projects:
GET {{baseUrl}}/api/v1/projects
Authorization: Bearer {{token}}POST Project:
POST {{baseUrl}}/api/v1/projects
Authorization: Bearer {{token}}
Content-Type: application/json
{
"name": "New Project"
}Insomnia
Import OpenAPI
- Open Insomnia
- Application > Preferences > Data > Import
- Choose From URL
- Enter:
http://localhost:3001/api/docs-json
Configure Auth
Set up Bearer Token authentication:
- Select a request
- Go to Auth tab
- Choose Bearer Token
- Enter your token
HTTPie
HTTPie provides a cleaner CLI experience:
# Install
brew install httpie
# GET request
http GET localhost:3001/api/v1/projects \
Authorization:"Bearer <token>"
# POST request
http POST localhost:3001/api/v1/projects \
Authorization:"Bearer <token>" \
name="New Project"VS Code REST Client
Create a .http file in VS Code:
### Variables
@baseUrl = http://localhost:3001
@token = your-bearer-token
### Get all projects
GET {{baseUrl}}/api/v1/projects
Authorization: Bearer {{token}}
### Create project
POST {{baseUrl}}/api/v1/projects
Authorization: Bearer {{token}}
Content-Type: application/json
{
"name": "New Project"
}Click Send Request above each request to execute.
Authentication Testing
Login Flow
# Register
curl -X POST http://localhost:3001/api/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
# Login
curl -X POST http://localhost:3001/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
# Response includes access token
{
"accessToken": "eyJ...",
"refreshToken": "...",
"user": { ... }
}API Key Authentication
curl -X GET http://localhost:3001/api/v1/projects \
-H "X-API-Key: your-api-key"Response Codes
| Code | Meaning | Action |
|---|---|---|
200 | Success | Request completed |
201 | Created | Resource created |
400 | Bad Request | Check request body |
401 | Unauthorized | Add/check auth token |
403 | Forbidden | Check permissions |
404 | Not Found | Resource doesn’t exist |
422 | Validation Error | Check field values |
500 | Server Error | Check server logs |
Related
Last updated on