api-request-profiler
v1.0.0
Published
Lightweight API request profiler for Node.js with Express middleware, CLI tool, and real-time performance monitoring
Maintainers
Readme
ApiRequestProfiler 🚀
📋 Table of Contents
🎯 Features
- Real-time Performance Monitoring - Track response times, throughput, error rates
- Payload Analysis - Monitor request/response sizes and content types
- Endpoint Profiling - URL-based performance analysis
- Multiple Integration Options - CLI, Express middleware, Koa middleware, standalone server
- Historical Data - Time-based trend analysis
- Minimal Overhead - High performance with minimal dependencies
🚀 Quick Start
CLI Usage
# Profile a single API endpoint
api-profiler --url https://api.example.com/users --method GET
# Profile with custom headers
api-profiler --url https://api.example.com/users --method POST --headers '{"Content-Type": "application/json"}' --body '{"name": "test"}'
# Continuous monitoring
api-profiler --url https://api.example.com/users --method GET --interval 5000 --duration 60000Express Middleware
import express from 'express';
import { createExpressMiddleware } from 'api-request-profiler/middleware/express.js';
const app = express();
const profiler = createExpressMiddleware();
app.use(profiler);
app.get('/api/users', (req, res) => {
res.json({ users: [] });
});
app.listen(3000);Standalone Server
import { createProfilerServer } from 'api-request-profiler/server.js';
const server = createProfilerServer({
port: 3001,
host: 'localhost'
});
server.start();📊 Metrics Collected
- Response Time: Average, min, max, percentiles
- Throughput: Requests per second
- Error Rate: Percentage of failed requests
- Payload Sizes: Request and response body sizes
- Status Codes: Distribution of HTTP status codes
- Content Types: Request and response content type analysis
🛠️ Installation
Requirements: Node.js 18.0.0 or higher
NPM
npm install api-request-profilerGlobal CLI Tool
npm install -g api-request-profiler
api-profiler --url https://api.example.com/usersFrom Source
git clone https://github.com/erencanucarr/api-request-profiler.git
cd api-request-profiler
npm start📈 Usage Scenarios
Development
Monitor API performance during development to catch performance issues early.
Testing
Analyze load testing results and identify bottlenecks.
Production
Track live system performance and detect performance degradation.
Debugging
Quickly identify performance issues with detailed request profiling.
🔧 Configuration
All configuration is done through environment variables or function parameters:
const profiler = createExpressMiddleware({
enablePayloadAnalysis: true,
enableRealTimeMetrics: true,
retentionPeriod: 24 * 60 * 60 * 1000, // 24 hours
maxRequests: 10000
});🤝 Contributing
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
git clone https://github.com/erencanucarr/api-request-profiler.git
cd api-request-profiler
npm install
npm run dev📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with Node.js built-in modules
- Inspired by the need for simple, effective API performance monitoring
- Thanks to all contributors and users
