@loan-risk/http-api
v1.0.5
Published
Express HTTP API for loan risk analysis engine
Maintainers
Readme
@loan-risk/http-api
Express HTTP API for Loan Risk Analyzer.
Features
- Loan Risk Analysis API
- Swagger Documentation
- Redis Caching
- Health Monitoring
- Metrics Endpoint
- OpenTelemetry Tracing
- API Key Authentication
- Usage Tracking
- Free Tier Limits
- Request Compression
- Docker Support
- Docker Health Checks
- TypeScript Support
Installation
pnpm add @loan-risk/http-apiEnvironment Variables
PORT=4000
REDIS_URL=redis://localhost:6379
API_KEYS=demo-key-1,demo-key-2Redis Setup
Start Redis using Docker:
docker run -d \
--name redis \
-p 6379:6379 \
redis:latestVerify Redis:
docker exec -it redis redis-cli pingExpected:
PONGStart Development Server
pnpm --filter @loan-risk/http-api devSwagger Documentation
http://localhost:4000/docsAuthentication
Protected endpoints require an API key.
Example:
x-api-key: demo-key-1If no API key is provided:
{
"success": false,
"error": {
"code": "MISSING_API_KEY"
}
}Free Tier Limits
Current plan:
100 requests per day per API keyWhen limit is exceeded:
{
"success": false,
"error": {
"code": "FREE_TIER_LIMIT_EXCEEDED"
}
}API Endpoints
Health Check
GET /api/v1/healthMetrics
GET /api/v1/metricsUsage Statistics
GET /api/v1/usage/:apiKeyExample:
GET /api/v1/usage/demo-key-1Analyze Loan Risk
POST /api/v1/analyzeHeaders:
x-api-key: demo-key-1
Content-Type: application/jsonRequest:
{
"fullName": "Aparna Nikam",
"age": 28,
"monthlyIncome": 90000,
"monthlyEMI": 15000,
"requestedLoanAmount": 500000,
"creditScore": 760,
"employmentType": "SALARIED"
}Response:
{
"success": true,
"data": {
"score": 85,
"riskLevel": "LOW",
"approved": true
}
}Docker
Build Image:
docker build -t loan-risk-api .Run Container:
docker run -d \
--name loan-risk-api \
-p 4000:4000 \
-e PORT=4000 \
-e REDIS_URL=redis://host.docker.internal:6379 \
loan-risk-apiCheck Logs:
docker logs loan-risk-apiHealth Check:
curl http://localhost:4000/api/v1/healthCI/CD
GitHub Actions automatically runs:
- Install
- Type Check
- Lint
- Build
- Tests
on every Pull Request and Push.
Automated Releases
Release workflow automatically creates GitHub releases from tagged versions.
Example:
git tag v1.0.2
git push origin v1.0.2Automated npm Publishing
Packages are automatically published to npm when a GitHub Release is published.
Supported packages:
- @loan-risk/core
- @loan-risk/logger
- @loan-risk/http-api
License
MIT © Aparna Nikam
