// Test and debug Next.js API routes, validate responses, check authentication, and troubleshoot API errors. Use when testing API endpoints, debugging 500 errors, validating API responses, or checking authentication flows.
| name | api-testing |
| description | Test and debug Next.js API routes, validate responses, check authentication, and troubleshoot API errors. Use when testing API endpoints, debugging 500 errors, validating API responses, or checking authentication flows. |
| allowed-tools | Read, Bash, Grep, Glob |
Expert assistance for testing and debugging Next.js API routes in the MantisNXT project.
# Test inventory API
curl -s "http://localhost:3000/api/inventory?limit=5"
# Test analytics API
curl -s "http://localhost:3000/api/analytics/recommendations?limit=5"
# Test supplier API
curl -s "http://localhost:3000/api/suppliers"
# Test stock movements
curl -s "http://localhost:3000/api/stock-movements?limit=5"
# Test health check
curl -s "http://localhost:3000/api/health"
# Login and get token
TOKEN=$(curl -s -X POST "http://localhost:3000/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"password"}' \
| jq -r '.token')
# Use token for authenticated request
curl -s "http://localhost:3000/api/protected-route" \
-H "Authorization: Bearer $TOKEN"
# Test creating inventory item
curl -X POST "http://localhost:3000/api/inventory" \
-H "Content-Type: application/json" \
-d '{
"sku": "TEST-001",
"name": "Test Product",
"quantity": 100
}'
# Test pricelist upload
curl -X POST "http://localhost:3000/api/suppliers/pricelists/upload" \
-F "file=@path/to/pricelist.xlsx" \
-F "supplierId=123"
All API routes are in src/app/api/:
src/app/api/
├── auth/
│ ├── login/route.ts
│ └── status/route.ts
├── inventory/route.ts
├── suppliers/
│ ├── route.ts
│ └── pricelists/upload/route.ts
├── analytics/
│ ├── recommendations/route.ts
│ └── predictions/route.ts
├── stock-movements/route.ts
├── health/route.ts
└── upload/route.ts
All API responses should follow this structure:
// Success response
{
"success": true,
"data": { /* response data */ },
"message": "Operation completed successfully"
}
// Error response
{
"success": false,
"error": "Error message",
"details": { /* additional error info */ }
}
# Quick response time check
time curl -s "http://localhost:3000/api/inventory" > /dev/null
# Test concurrent requests
for i in {1..10}; do
curl -s "http://localhost:3000/api/health" &
done
wait
Required for API testing:
DATABASE_URL=postgresql://...
NEXT_PUBLIC_API_URL=http://localhost:3000
NODE_ENV=development