Stack Library API is a RESTful API built using Node.js and Express.js that demonstrates modern backend development practices.
This project includes:
- API Key Authentication
- HATEOAS Implementation
- CRUD Operations
- Pagination
- Rate Limiting
- Logging
- Usage Tracking
- Modular Architecture
- Global Error Handling
This API simulates a real-world production-ready backend system using a dummy JSON-based database.
- Login-based access
- API Key generation
- Header-based API authentication
Header format:
x-api-key: stack_xxxxxxxxx
After login, the API returns navigational links such as:
- Generate API Key
- Get Books
- Access Resources
Supports:
- Create books
- Read books
- Pagination support
- Resource access control
Supported query parameters:
?page=1
&limit=5
Example:
GET /api/books?page=1&limit=5
Limits:
5 Requests per minute
Prevents:
- Server overload
- API abuse
Logs include:
- HTTP Method
- Route
- Status Code
- Response Time
Tracks:
- Request count
- Last used timestamp
Example:
"usage": {
"requestCount": 12,
"lastUsed": "2026-04-16T08:50:00Z"
}
Centralized error responses.
Example:
{
"success": false,
"error": "Route not found"
}
project-root
│
├── config
│ └── db.js
│
├── controllers
│ ├── authController.js
│ ├── bookController.js
│ ├── usageController.js
│ └── docsController.js
│
├── middleware
│ ├── apiKeyMiddleware.js
│ ├── rateLimiter.js
│ ├── errorHandler.js
│
├── routes
│ ├── authRoutes.js
│ ├── bookRoutes.js
│ ├── usageRoutes.js
│ └── docsRoutes.js
│
├── data
│ ├── users.json
│ └── books.json
│
├── utils
│ └── generateApiKey.js
│
├── .env
├── app.js
├── package.json
└── README.md
git clone <repository-url>
npm install
Example:
PORT=5000
API_KEY_HEADER=x-api-key
RATE_LIMIT_MAX=5
RATE_LIMIT_WINDOW=60000
npm start
or
node app.js
Server runs at:
http://localhost:5000
POST /api/login
Body:
{
"email": "user@example.com",
"password": "password"
}
Response:
{
"success": true,
"apiKey": "stack_xxxxx",
"links": [...]
}
Add header:
x-api-key: stack_xxxxx
Then access:
GET /api/books
POST /api/login
Body:
{
"email": "user@example.com",
"password": "password"
}
POST /api/generate-api-key
GET /api/books
Optional:
?page=1
&limit=5
POST /api/books
Body:
{
"title": "Book Title",
"author": "Author Name"
}
GET /api/usage
GET /api/docs
- Node.js
- Express.js
- UUID
- Morgan (Logger)
- Express Rate Limit
- dotenv
- JSON File Database
This project demonstrates:
- RESTful API design
- API Key authentication
- HATEOAS implementation
- Middleware architecture
- Pagination logic
- Rate limiting
- Logging system
- Usage analytics
- Modular backend structure
Possible upgrades:
- Database Integration (MongoDB / PostgreSQL)
- JWT Authentication
- Swagger Documentation
- Role-Based Access Control
- API Versioning
StackWiseDev Developer
This project is for learning and educational purposes.