An open API service indexing awesome lists of open source software.

https://github.com/chhedadhruv/inspirational-quotes-api

๐ŸŽฏ A modern, secure REST API serving 2000+ inspirational quotes with Docker support, rate limiting, and health monitoring. Built with Node.js & Express.
https://github.com/chhedadhruv/inspirational-quotes-api

api backend daily-quotes docker dotenv express health-check helmet inspiration inspirational-quotes javascript json-api motivation nodejs pagination productivity quotes rate-limiting rest-api self-improvement

Last synced: 5 days ago
JSON representation

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

Awesome Lists containing this project

README

          

# ๐Ÿ“š Quote API

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

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
[![Express](https://img.shields.io/badge/Express-5.1.0-blue.svg)](https://expressjs.com/)
[![Docker](https://img.shields.io/badge/Docker-Ready-blue.svg)](https://www.docker.com/)
[![Cloudflare](https://img.shields.io/badge/Cloudflare-Tunnel-orange.svg)](https://www.cloudflare.com/)

[Features](#-features) โ€ข [Quick Start](#-quick-start) โ€ข [API Documentation](#-api-documentation) โ€ข [Configuration](#-configuration) โ€ข [Docker](#-docker-deployment)

---

## โœจ 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](https://img.shields.io/badge/Node.js-18+-green?style=flat-square&logo=node.js)
![npm](https://img.shields.io/badge/npm-latest-red?style=flat-square&logo=npm)
![Docker](https://img.shields.io/badge/Docker-optional-blue?style=flat-square&logo=docker)

### Installation

```bash
# 1๏ธโƒฃ Clone the repository
git clone
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
```bash
git clone && cd quote-api && npm install && cp .env.example .env && npm start
```

---

## ๐Ÿณ Docker Deployment

๐Ÿ”ง Using Docker Compose (Recommended)

```bash
# Build and start services
docker-compose up -d

# View logs
docker-compose logs -f quote-api

# Stop services
docker-compose down
```

๐Ÿ“ฆ Manual Docker Build

```bash
# 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
```http
GET /api/quote/random
```

๐Ÿ“ Response Example

```json
{
"_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
```http
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

```json
{
"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
```http
GET /api/quotes/search?q=success
```

**Parameters:**
- `q` (required): Search query

๐Ÿ“ Response Example

```json
{
"query": "success",
"total": 15,
"results": [...]
}
```

#### ๐Ÿ‘ค Quotes by Author
```http
GET /api/quotes/author/steve-jobs
```

#### ๐Ÿท๏ธ Quotes by Tag
```http
GET /api/quotes/tag/motivation
```

#### ๐Ÿ†” Get Quote by ID
```http
GET /api/quote/{id}
```

#### ๐Ÿ“… Quotes by Date
```http
GET /api/quotes/date/2023-01-01
```

#### ๐Ÿ“ Filter by Length
```http
GET /api/quotes/length?min=50&max=100
```

**Parameters:**
- `min` (optional): Minimum character length
- `max` (optional): Maximum character length

#### ๐Ÿท๏ธ Get All Tags
```http
GET /api/tags
```

๐Ÿ“ Response Example

```json
{
"total": 25,
"tags": ["inspiration", "motivation", "success", "wisdom", "life"]
}
```

#### ๐Ÿฅ Health Check
```http
GET /health
```

๐Ÿ“ Response Example

```json
{
"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:

```bash
cp .env.example .env
```

**Available Environment Variables:**

```env
# ๐Ÿ–ฅ๏ธ 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**

```bash
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

```bash
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

```yaml
tunnel:
credentials-file: /etc/cloudflared/quote-api-tunnel.json

ingress:
- hostname:
service: http://quote-api:3000
- service: http_status:404
```

### ๐Ÿš€ Deploy

```bash
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:

```bash
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

```bash
# ๐ŸŽฏ 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

```javascript
// 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

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

```bash
# 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

```bash
# 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](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! ๐Ÿš€*