Skip to content

slowlyh/Api

Repository files navigation

πŸš€ API Service

Node.js Express Docker License

Modern RESTful API with AI chat, media downloaders, and real-time monitoring.

✨ Features

  • πŸ€– AI Chat (GPT OSS 120B)
  • πŸ“₯ Media Downloaders (Facebook, Twitter/X, CapCut, MediaFire, SnackVideo)
  • 🎲 Random Content (Anime, Waifu, Blue Archive)
  • πŸ› οΈ Image Tools (Unblur, Upscale)
  • πŸ“Š Real-time Statistics
  • πŸ”’ Multi-tier Rate Limiting
  • 🐳 Docker Ready

πŸ“‹ Info

Stack: Node.js 18+ β€’ Express.js 4.x β€’ Docker
Port: 1038 (configurable)
Version: 2.1.0

πŸ“ Structure

β”œβ”€ src/           # API endpoints (auto-loaded)
β”œβ”€ client/        # React frontend (Vite + React + TailwindCSS)
β”‚  β”œβ”€ src/        # React source code
β”‚  β”‚  β”œβ”€ components/  # Reusable components
β”‚  β”‚  β”œβ”€ pages/       # Page components
β”‚  β”‚  └─ App.jsx      # Main app + routing
β”‚  └─ vite.config.js  # Vite configuration
β”œβ”€ config/        # Server configuration
β”œβ”€ middlewares/   # Rate limiting, validation
β”œβ”€ utils/         # Logger, cache, metrics
β”œβ”€ dist/          # React build output (served by Express)
β”œβ”€ metadata.json  # API branding
└─ endpoints.json # Endpoint definitions

🎨 Frontend

The project includes a modern React frontend built with:

  • ⚑ Vite - Lightning fast build tool
  • βš›οΈ React 18 - Latest React features
  • 🎨 TailwindCSS - Utility-first CSS
  • 🧭 React Router - Client-side routing
  • 🎯 Lucide Icons - Beautiful icons
  • πŸ“± Responsive - Mobile-first design

React-only frontend - The Express server serves the React SPA from dist/ directory.

πŸš€ Quick Start

Production Setup

# 1. Install backend dependencies
npm install

# 2. Configure environment
cp .env.example .env
# Edit metadata.json with your info

# 3. Install React dependencies
npm run client:install

# 4. Build React app
npm run client:build

# 5. Start server
npm start
# β†’ http://localhost:1038

Development Mode

# Terminal 1: Start backend API
npm run dev

# Terminal 2: Start React dev server (with HMR)
npm run client
# β†’ http://localhost:3000 (proxies to :1038)

Docker

docker-compose up -d

βš™οΈ Configuration

metadata.json - API branding:

{
  "creator": "Your Name",
  "apititle": "Your API",
  "github": "https://github.com/you",
  "whatsapp": "https://wa.me/phone",
  "favicon": "/public/favicon.ico"
}

.env - Server config:

PORT=1038
NODE_ENV=production
LOG_LEVEL=info
RATE_LIMIT_MAX_REQUESTS=30

πŸ“‘ Endpoints

AI

GET /ai/oss?text=<query>  # GPT chat

Downloaders

GET /download/capcut?url=<url>
GET /download/facebook?url=<url>
GET /download/x?url=<url>
GET /download/snackvideo?url=<url>
GET /download/mediafire?url=<url>

Random Content

GET /random/ba        # Blue Archive
GET /random/waifu     # Anime waifu
GET /random/papayang  # Romantic

Tools

GET /tools/unblur?url=<image_url>  # Unblur & upscale

Monitoring

GET /api/status              # Server status
GET /api/health              # Health metrics
GET /api/stats/realtime      # Live stats
GET /api/stats/top?limit=10  # Top endpoints
GET /api/cache/stats         # Cache stats
GET /metrics                 # Prometheus

Full documentation: http://localhost:1038/docs

πŸ”§ Add Endpoint

  1. Create src/category/name.js:
module.exports = function (app) {
  app.get("/category/name", async (req, res) => {
    try {
      const { param } = req.query;
      if (!param) return res.status(400).json({ status: false, error: 'Required' });
      
      const result = await yourLogic(param);
      res.json({ status: true, result });
    } catch (error) {
      res.status(500).json({ status: false, error: error.message });
    }
  });
};
  1. Add to endpoints.json:
{
  "Category": [{
    "name": "Name",
    "desc": "Description",
    "method": "GET",
    "path": "/category/name?param="
  }]
}
  1. Restart server (auto-loaded)

🐳 Docker

# With Docker Compose (includes Prometheus + Grafana)
docker-compose up -d

# Manual
docker build -t api .
docker run -d -p 1038:1038 --name api api

Services:

See DEPLOYMENT.md for details.

πŸ“Š Monitoring

Pages:

Endpoints:

  • /metrics - Prometheus metrics
  • /api/health - System health
  • /api/stats/realtime - Live stats

Logs: logs/ directory (daily rotation)

πŸ“€ Response Format

Success:

{
  "status": true,
  "creator": "<from metadata.json>",
  "result": { ... }
}

Error:

{
  "status": false,
  "creator": "<from metadata.json>",
  "error": "Error message"
}

⚠️ Error Codes

  • 400 - Invalid parameters
  • 404 - Endpoint not found
  • 429 - Rate limit exceeded
  • 500 - Server error

πŸ”’ Rate Limits

  • General: 30 req/min
  • AI: 5 req/min
  • Downloads: 10 req/min
  • Monitoring: 200 req/min
  • Static files: Unlimited

πŸ› οΈ Development

Guidelines:

  • Use async/await
  • Add error handling
  • Validate inputs
  • Follow existing patterns

Scripts:

# Backend
npm start              # Start server
npm run dev            # Dev mode (nodemon)

# React Frontend
npm run client:install # Install React dependencies
npm run client         # Start React dev server (port 3000)
npm run client:build   # Build React for production

# Docker
npm run docker:build   # Build image
npm run docker:up      # Start compose
npm run docker:down    # Stop compose
npm run docker:logs    # View logs

Environment:

  • PORT - Server port (default: 1038)
  • NODE_ENV - Environment mode
  • LOG_LEVEL - Log level (info/warn/error)
  • RATE_LIMIT_MAX_REQUESTS - Rate limit (default: 30/min)

🀝 Contributing

  1. Fork repository
  2. Create feature branch
  3. Follow code style
  4. Test changes
  5. Submit pull request

πŸ› Troubleshooting

Port in use:

# Windows
netstat -ano | findstr :1038
# Linux/Mac
lsof -i :1038

Module errors:

npm install

Docker issues:

docker-compose logs api
docker-compose restart api

πŸ“š Resources

πŸ“ Configuration

Edit metadata.json for branding
Edit endpoints.json for endpoint docs
Edit .env for server settings

πŸ“„ License

MIT License - see LICENSE file for details


About

A simple rest api's use express.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages