@chengyixu/api-health
v1.0.0
Published
Monitor API endpoints from the command line. Check response times, status codes, SSL certificate expiry, and get a beautiful dashboard.
Downloads
53
Maintainers
Readme
@chengyixu/api-health
Monitor API endpoints from the command line. Check response times, status codes, SSL certificate expiry, and get a beautiful dashboard.
Features
- Dashboard view — Color-coded status, response times, SSL expiry at a glance
- SSL certificate checking — See issuer, expiry date, TLS protocol, days until expiry
- Multiple endpoints — Check many APIs in parallel with configurable concurrency
- Watch mode — Continuously monitor endpoints at any interval
- JSON output — Pipe results to other tools or store for analysis
- Detailed reports — Full response headers, security headers, content info
- Config file support — Save your endpoints in
api-health.jsonfor easy re-runs - CI/CD friendly — Exits with code 1 if any endpoint is down or returns 5xx
Install
npm install -g @chengyixu/api-healthUsage
Quick check
# Check one or more endpoints
api-health check https://api.example.com https://api2.example.com
# Auto-prepends https:// if missing
api-health check api.github.com google.comDashboard output
API Health Dashboard
2024-01-15T10:30:00.000Z
┌───┬─────────────────────────────────┬──────────┬──────────┬──────────┬────────────┐
│ │ Endpoint │ Status │ Time │ Size │ SSL Expiry │
├───┼─────────────────────────────────┼──────────┼──────────┼──────────┼────────────┤
│ ✔ │ https://api.github.com │ 200 │ 142ms │ 2.1KB │ 76d │
├───┼─────────────────────────────────┼──────────┼──────────┼──────────┼────────────┤
│ ✔ │ https://httpbin.org/get │ 200 │ 312ms │ 243B │ 151d │
├───┼─────────────────────────────────┼──────────┼──────────┼──────────┼────────────┤
│ ✘ │ https://down.example.com │ ERR │ - │ - │ - │
└───┴─────────────────────────────────┴──────────┴──────────┴──────────┴────────────┘
Summary: 2/3 healthy | 1 errors | avg 227ms
SSL Warnings:
⚠ https://expiring.example.com — SSL expires in 12 daysSSL certificate check
api-health ssl google.com github.com stripe.comJSON output (for scripting/CI)
api-health check --json https://api.example.comDetailed report
api-health check --detailed https://api.example.comShows response headers, security headers, full SSL certificate info.
Watch mode
# Monitor every 30 seconds (default)
api-health watch https://api.example.com
# Custom interval
api-health watch -i 10 https://api.example.com https://api2.example.comConfig file
Create an api-health.json in your project:
api-health initThis generates:
{
"endpoints": [
{
"url": "https://api.github.com",
"name": "GitHub API",
"expectedStatus": 200
},
{
"url": "https://httpbin.org/get",
"name": "HTTPBin"
}
],
"defaults": {
"timeout": 10000,
"method": "GET"
}
}Then just run:
api-health checkOptions
| Flag | Description | Default |
|------|-------------|---------|
| -t, --timeout <ms> | Request timeout | 10000 |
| -m, --method <method> | HTTP method | GET |
| -H, --header <key:value> | Custom header (repeatable) | - |
| -j, --json | JSON output | false |
| -d, --detailed | Detailed report | false |
| -c, --config <path> | Config file path | auto-detect |
| --concurrency <n> | Max parallel requests | 5 |
| --no-ssl | Skip SSL check | false |
Use Cases
- Pre-deploy checks — Verify all your APIs are healthy before deploying
- SSL monitoring — Get warned before certificates expire
- CI/CD pipelines — Add health checks to your deployment pipeline
- On-call dashboards — Quick terminal dashboard for incident response
- Performance monitoring — Track response time trends
Programmatic API
import { checkEndpoint, checkMultipleEndpoints } from '@chengyixu/api-health';
const result = await checkEndpoint('https://api.example.com', {
timeout: 5000,
method: 'GET',
});
console.log(result.status); // 200
console.log(result.responseTime); // 142
console.log(result.ssl?.daysUntilExpiry); // 76License
MIT
