Skip to content

🎯 A modern, secure REST API serving 2000+ inspirational quotes with Docker support, rate limiting, and health monitoring. Built with Node.js & Express.

License

Notifications You must be signed in to change notification settings

chhedadhruv/inspirational-quotes-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Quote API

A modern, secure, and feature-rich REST API for inspirational quotes

License: MIT Node.js Express Docker Cloudflare

Features β€’ Quick Start β€’ API Documentation β€’ Configuration β€’ Docker


✨ Features

🎯 Core Features

  • 🎲 Random quote generation
  • πŸ” Advanced search capabilities
  • 🏷️ Tag-based filtering
  • πŸ“… Date-based queries
  • πŸ“ Length filtering
  • πŸ‘€ Author-based search

πŸ› οΈ Technical Features

  • βš™οΈ Environment configuration
  • πŸ₯ Health monitoring
  • πŸ› Debug mode
  • 🎨 Pretty JSON responses
  • πŸ“ Enhanced response objects
  • πŸ”’ Security-first design

πŸš€ Deployment

  • 🐳 Docker ready
  • ☁️ Cloudflare tunnel integration
  • πŸ“Š Pagination support
  • πŸ”„ Hot reload for development

πŸ”’ Security

  • πŸ›‘οΈ Rate limiting
  • πŸ” Secure headers
  • 🚫 Input validation
  • 🌐 CORS protection
  • πŸ”’ Environment-based security

πŸš€ Quick Start

Prerequisites

Node.js npm Docker

Installation

# 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:3000

Alternative: One-liner setup

git clone <repository-url> && cd quote-api && npm install && cp .env.example .env && npm start

🐳 Docker Deployment

πŸ”§ 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-api

πŸ“– API Documentation

🌐 Base URL

http://localhost:3000/api

πŸ’‘ Pro Tip: The API prefix is configurable via the API_PREFIX environment variable (default: /api)

πŸ“‹ Endpoints Overview

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

πŸ” Detailed Endpoint Documentation

🎲 Random Quote

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 All Quotes

GET /api/quotes?page=1&limit=10

Parameters:

  • 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"
    }
  ]
}

πŸ” Search Quotes

GET /api/quotes/search?q=success

Parameters:

  • q (required): Search query
πŸ“ Response Example
{
  "query": "success",
  "total": 15,
  "results": [...]
}

πŸ‘€ Quotes by Author

GET /api/quotes/author/steve-jobs

🏷️ Quotes by Tag

GET /api/quotes/tag/motivation

πŸ†” Get Quote by ID

GET /api/quote/{id}

πŸ“… Quotes by Date

GET /api/quotes/date/2023-01-01

πŸ“ Filter by Length

GET /api/quotes/length?min=50&max=100

Parameters:

  • min (optional): Minimum character length
  • max (optional): Maximum character length

🏷️ Get All Tags

GET /api/tags
πŸ“ Response Example
{
  "total": 25,
  "tags": ["inspiration", "motivation", "success", "wisdom", "life"]
}

πŸ₯ Health Check

GET /health
πŸ“ Response Example
{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00.000Z",
  "uptime": 3600,
  "environment": "development",
  "version": "v1"
}

βš™οΈ Configuration

πŸ”§ Environment Variables

πŸ“‹ View All Environment Variables

Copy the .env.example file to .env and customize the values:

cp .env.example .env

Available 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

πŸ”’ Security Features

πŸ›‘οΈ Built-in Security

  • Rate limiting (configurable)
  • Secure headers via Helmet.js
  • Input validation
  • CORS protection
  • No information leakage

βš™οΈ Configurable Security

  • Environment-based toggles
  • Flexible rate limiting
  • Custom CORS policies
  • Debug mode controls
  • Production optimizations

πŸ› οΈ Development Features

πŸ› Debug & Testing

  • Debug mode logging
  • Pretty JSON formatting
  • Environment awareness
  • Hot reload support
  • Health monitoring

πŸ“Š Monitoring

  • Built-in health checks
  • Process monitoring
  • Environment info
  • Enhanced error messages
  • Rate limit headers

🌐 Cloudflare Tunnel Setup

☁️ Configure Cloudflare Tunnel
  1. Configure your tunnel in cloudflared/config.yml
  2. Update docker-compose.yml with your tunnel ID
  3. Deploy with Docker Compose
docker-compose up -d

🏑 Home Server Deployment (Self-Hosting)

βš™οΈ Deploy from Your Home PC using Docker + Cloudflare Tunnel

πŸ”§ Requirements

  • Ubuntu/Linux-based home server
  • Docker + Docker Compose
  • Cloudflared installed and authenticated
  • Cloudflare DNS set up with your domain (e.g., quotes.dhruvchheda.com)

πŸ“ Folder Structure

quote-stack/
β”œβ”€β”€ quote-api/                   # Express API source
β”œβ”€β”€ cloudflared/
β”‚   β”œβ”€β”€ config.yml               # Tunnel configuration
β”‚   └── quote-api-tunnel.json    # Tunnel credentials
└── docker-compose.yml          # Service orchestration

πŸ“ cloudflared/config.yml

tunnel: <your-tunnel-id>
credentials-file: /etc/cloudflared/quote-api-tunnel.json

ingress:
  - hostname: <your-domain>
    service: http://quote-api:3000
  - service: http_status:404

πŸš€ Deploy

docker-compose up -d

βœ… Your API will be available publicly at: https://

πŸ”„ Auto-Start on Reboot (Optional)

Enable automatic startup of Docker and cloudflared on server reboot:

sudo systemctl enable docker
sudo systemctl enable cloudflared

πŸ“ Project Structure

quote-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

πŸš€ Available Scripts

# 🎯 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)

πŸ’‘ Usage Examples

🟨 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

⚑ Performance

  • Fast response times
  • Memory efficient
  • Scalable architecture
  • Docker-ready deployment

πŸ“Š Monitoring

  • Health check endpoint
  • Debug mode logging
  • Rate limit headers
  • Environment info
  • Process monitoring

πŸ“ˆ Monitoring Commands

# View Docker logs
docker-compose logs -f

# Check health status
curl http://localhost:3000/health

# Monitor in debug mode
DEBUG=true npm start

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. 🍴 Fork the repository
  2. 🌟 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ”„ Open a Pull Request

πŸ“‹ Development Guidelines

  • Follow existing code style
  • Add tests for new features
  • Update documentation
  • Ensure all tests pass
  • Use meaningful commit messages

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Express.js - Fast, unopinionated web framework
  • Helmet.js - Security middleware
  • Docker - Containerization platform
  • Cloudflare - CDN and security services

🌟 Star this repository if you find it helpful!

Built with ❀️ using Node.js and Express

Happy coding! πŸš€

About

🎯 A modern, secure REST API serving 2000+ inspirational quotes with Docker support, rate limiting, and health monitoring. Built with Node.js & Express.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published