A modern, secure, and feature-rich REST API for inspirational quotes
Features β’ Quick Start β’ API Documentation β’ Configuration β’ Docker
|
|
|
|
# 1οΈβ£ Clone the repository
git clone <repository-url>
cd quote-api
# 2οΈβ£ Install dependencies
npm install
# 3οΈβ£ Set up environment variables
cp .env.example .env
# Edit .env file with your preferred settings
# 4οΈβ£ Start the development server
npm start
# π Your API is now running at http://localhost:3000git clone <repository-url> && cd quote-api && npm install && cp .env.example .env && npm startπ§ Using Docker Compose (Recommended)
# Build and start services
docker-compose up -d
# View logs
docker-compose logs -f quote-api
# Stop services
docker-compose downπ¦ Manual Docker Build
# Build the image
docker build -t quote-api .
# Run the container
docker run -p 3000:3000 --env-file .env quote-apihttp://localhost:3000/api
π‘ Pro Tip: The API prefix is configurable via the
API_PREFIXenvironment variable (default:/api)
| Category | Endpoint | Description | Example |
|---|---|---|---|
| π² Random | GET /api/quote/random |
Get a random quote | View |
GET /api/quotes |
Get all quotes (paginated) | View | |
| π Search | GET /api/quotes/search |
Search quotes by content | View |
GET /api/quotes/author/:name |
Get quotes by author | View | |
GET /api/quotes/tag/:tag |
Get quotes by tag | View | |
| π Filter | GET /api/quotes/date/:date |
Get quotes by date | View |
GET /api/quotes/length |
Filter by character length | View | |
GET /api/quote/:id |
Get specific quote by ID | View | |
| π·οΈ Meta | GET /api/tags |
Get all available tags | View |
GET /health |
Health check endpoint | View |
GET /api/quote/randomπ Response Example
{
"_id": "quote-id-123",
"content": "The only way to do great work is to love what you do.",
"author": "Steve Jobs",
"tags": ["work", "passion", "success"],
"length": 49,
"dateAdded": "2023-01-01"
}GET /api/quotes?page=1&limit=10Parameters:
page(optional): Page number (default: 1)limit(optional): Number of quotes per page (default: all)
π Response Example
{
"page": 1,
"limit": 10,
"total": 100,
"results": [
{
"_id": "quote-id-123",
"content": "Quote content here...",
"author": "Author Name",
"tags": ["tag1", "tag2"],
"length": 50,
"dateAdded": "2023-01-01"
}
]
}GET /api/quotes/search?q=successParameters:
q(required): Search query
π Response Example
{
"query": "success",
"total": 15,
"results": [...]
}GET /api/quotes/author/steve-jobsGET /api/quotes/tag/motivationGET /api/quote/{id}GET /api/quotes/date/2023-01-01GET /api/quotes/length?min=50&max=100Parameters:
min(optional): Minimum character lengthmax(optional): Maximum character length
GET /api/tagsπ Response Example
{
"total": 25,
"tags": ["inspiration", "motivation", "success", "wisdom", "life"]
}GET /healthπ Response Example
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 3600,
"environment": "development",
"version": "v1"
}π View All Environment Variables
Copy the .env.example file to .env and customize the values:
cp .env.example .envAvailable Environment Variables:
# π₯οΈ Server Configuration
PORT=3000 # Server port
NODE_ENV=development # Environment mode (development/production)
# π Rate Limiting Configuration
RATE_LIMIT_WINDOW=60000 # Rate limit window in milliseconds
RATE_LIMIT_MAX=60 # Maximum requests per window
# π‘οΈ Security Headers
HELMET_ENABLED=true # Enable/disable security headers
# π CORS Configuration
CORS_ORIGIN=* # Allowed origins
CORS_METHODS=GET,POST,PUT,DELETE,OPTIONS
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With
# π‘ API Configuration
API_VERSION=v1 # API version for display
API_PREFIX=/api # API route prefix
# π οΈ Development Tools
DEBUG=false # Enable debug logging
PRETTY_PRINT_JSON=true # Pretty print JSON in development
# π Monitoring
HEALTH_CHECK_ENABLED=true # Enable health check endpoint
METRICS_ENABLED=false # Enable metrics collection|
π‘οΈ Built-in Security
|
βοΈ Configurable Security
|
|
π Debug & Testing
|
π Monitoring
|
βοΈ Configure Cloudflare Tunnel
- Configure your tunnel in
cloudflared/config.yml - Update
docker-compose.ymlwith your tunnel ID - Deploy with Docker Compose
docker-compose up -dβοΈ Deploy from Your Home PC using Docker + Cloudflare Tunnel
- Ubuntu/Linux-based home server
- Docker + Docker Compose
- Cloudflared installed and authenticated
- Cloudflare DNS set up with your domain (e.g., quotes.dhruvchheda.com)
quote-stack/
βββ quote-api/ # Express API source
βββ cloudflared/
β βββ config.yml # Tunnel configuration
β βββ quote-api-tunnel.json # Tunnel credentials
βββ docker-compose.yml # Service orchestrationtunnel: <your-tunnel-id>
credentials-file: /etc/cloudflared/quote-api-tunnel.json
ingress:
- hostname: <your-domain>
service: http://quote-api:3000
- service: http_status:404docker-compose up -dβ Your API will be available publicly at: https://
Enable automatic startup of Docker and cloudflared on server reboot:
sudo systemctl enable docker
sudo systemctl enable cloudflaredquote-api/
βββ π index.js # Main application file
βββ π quotes.json # Quote database
βββ π³ Dockerfile # Docker configuration
βββ π³ docker-compose.yml # Multi-service setup
βββ π¦ package.json # Dependencies
βββ π README.md # Documentation
βββ π§ .env.example # Environment variables template
βββ π§ .env # Environment variables (local)
βββ π« .gitignore # Git ignore rules
# π― Production
npm start # Start the production server
# π οΈ Development
npm run dev # Start development server with hot reload
# π§ͺ Testing
npm test # Run tests (to be implemented)π¨ JavaScript/Node.js
// Get a random quote
const response = await fetch('http://localhost:3000/api/quote/random');
const quote = await response.json();
console.log(`"${quote.content}" - ${quote.author}`);
// Search for quotes
const searchResponse = await fetch('http://localhost:3000/api/quotes/search?q=success');
const searchResults = await searchResponse.json();
console.log(`Found ${searchResults.total} quotes about success`);π Python
import requests
# Get a random quote
response = requests.get('http://localhost:3000/api/quote/random')
quote = response.json()
print(f'"{quote["content"]}" - {quote["author"]}')
# Get quotes by author
einstein_quotes = requests.get('http://localhost:3000/api/quotes/author/einstein')
print(f"Found {einstein_quotes.json()['total']} Einstein quotes")π‘ cURL
# Get a random quote
curl -X GET http://localhost:3000/api/quote/random
# Search quotes with pretty output
curl -X GET "http://localhost:3000/api/quotes/search?q=motivation" | jq
# Get health status
curl -X GET http://localhost:3000/health|
β‘ Performance
|
π Monitoring
|
# View Docker logs
docker-compose logs -f
# Check health status
curl http://localhost:3000/health
# Monitor in debug mode
DEBUG=true npm startWe welcome contributions! Please follow these steps:
- π΄ Fork the repository
- π Create a feature branch (
git checkout -b feature/amazing-feature) - π Commit your changes (
git commit -m 'Add amazing feature') - π Push to the branch (
git push origin feature/amazing-feature) - π Open a Pull Request
- Follow existing code style
- Add tests for new features
- Update documentation
- Ensure all tests pass
- Use meaningful commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Express.js - Fast, unopinionated web framework
- Helmet.js - Security middleware
- Docker - Containerization platform
- Cloudflare - CDN and security services