Skip to content
Adzy-xyzPublic

About

With Base @synshin9

Resources

Stars

1 star

Watchers

0 watching

Forks

Β 
Β 

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

InuSoft API

A lightweight, auto-loading REST API built with Express.js that automatically registers endpoints from the file system. Features elegant documentation and error pages with consistent styling.

Deploy to Vercel

Overview

InuSoft API is a modern REST API implementation that automatically loads endpoints from the api/ directory. It features a clean documentation interface, automatic endpoint registration, and a service-layer architecture for better code organization.

Features

  • πŸ”„ Auto-Loading Endpoints: Automatically registers API endpoints from file structure
  • πŸ“š Beautiful Documentation: Interactive API documentation with search functionality
  • 🎨 Consistent Styling: Elegant UI with gradient themes and responsive design
  • πŸ”§ Service Layer Architecture: Separated business logic for maintainability
  • πŸ“Š Request Logging: Automatic API request logging with response times
  • πŸš€ Error Handling: Custom 404 and 500 error pages with helpful UX
  • ⚑ Lightweight: Minimal dependencies and fast performance

Project Structure

Restfull-Api/
β”œβ”€β”€ api/                           # API endpoints (auto-loaded)
β”‚   β”œβ”€β”€ ai/                       # AI-related endpoints
β”‚   β”‚   β”œβ”€β”€ gpt.js               # GPT chat endpoint
β”‚   β”‚   └── write-cream.js       # Content writing endpoint
β”‚   └── random/                   # Random data endpoints
β”‚       └── bluearchive.js       # Blue Archive related data
β”œβ”€β”€ public/                       # Static files
β”‚   β”œβ”€β”€ index.html               # API documentation
β”‚   β”œβ”€β”€ 404.html                 # Custom 404 error page
β”‚   └── 500.html                 # Custom 500 error page
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                     # Application configuration
β”‚   β”‚   β”œβ”€β”€ index.js            # Main app setup
β”‚   β”‚   β”œβ”€β”€ middleware.js       # Middleware configuration
β”‚   β”‚   └── responseFormatter.js # Response formatting
β”‚   β”œβ”€β”€ services/                # Business logic layer
β”‚   β”‚   └── ai/
β”‚   β”‚       └── gptService.js   # GPT service logic
β”‚   └── utils/                   # Utility functions
β”‚       β”œβ”€β”€ loader.js           # Auto-loading utility
β”‚       β”œβ”€β”€ logger.js           # Logging utility
β”‚       β”œβ”€β”€ color.js            # Console colors
β”‚       └── logApiRequest.js    # Request logging
β”œβ”€β”€ server.js                    # Application entry point
β”œβ”€β”€ package.json
└── vercel.json                  # Vercel deployment config

API Endpoints

Available Endpoints

Endpoint Methods Category Description
GET /api/ai/gpt GET, POST AI GPT chat completion endpoint
GET /api/ai/write-cream GET, POST AI Content writing assistance
GET /api/random/bluearchive GET Random Blue Archive related data
GET /api/openapi.json GET Documentation API specification
GET / GET Documentation Web interface

Endpoint Structure

Each endpoint file follows this structure:

export default {
    name: "Endpoint Name",
    description: "Endpoint description",
    category: "Category",
    methods: ["GET", "POST"], // Supported HTTP methods
    params: ["param1", "param2"], // Expected parameters
    paramsSchema: { // Optional parameter validation
        param1: { type: "string", required: true }
    },
    
    async run(req, res) {
        try {
            // Your endpoint logic here
            const result = await someService.process(req.query);
            
            res.json({
                success: true,
                data: result,
                timestamp: new Date().toISOString(),
                attribution: "@synshin9"
            });
        } catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
}

Example: GPT Endpoint

File: api/ai/gpt.js

import GptService from '../../src/services/ai/gptService.js';

export default {
    name: "GPT Chat",
    description: "Chat completion using GPT models",
    category: "AI",
    methods: ["GET", "POST"],
    params: ["message", "model"],
    
    async run(req, res) {
        try {
            const { message, model = "gpt-3.5-turbo" } = req.method === 'GET' ? req.query : req.body;
            
            if (!message) {
                return res.status(400).json({
                    success: false,
                    error: "Message parameter is required"
                });
            }
            
            const result = await GptService.process(message, { model });
            
            res.json({
                success: true,
                data: result
            });
            
        } catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
}

Service Layer Example

File: src/services/ai/gptService.js

export class GptService {
    static async process(message, options = {}) {
        // Business logic implementation
        return {
            response: `Processed: ${message}`,
            model: options.model || 'default',
            timestamp: new Date().toISOString()
        };
    }
}

export default GptService;

Setup and Installation

  1. Clone the repository
    git clone https://github.com/synshin9/Restfull-Api.git
    cd Restfull-Api
  2. Install dependencies
    npm install
  3. Start the development server
    npm run dev
  4. Access the API

Vercel Deployment

The project includes vercel.json for zero-config deployment:

npm i -g vercel
vercel

Environment Variables

Create a .env file for environment-specific configurations:

PORT=3000
NODE_ENV=production

Adding New Endpoints

  1. Create Endpoint File

Create a new JavaScript file in the api/ directory:

// api/weather/forecast.js
export default {
    name: "Weather Forecast",
    description: "Get weather forecast for a location",
    category: "Weather",
    methods: ["GET"],
    params: ["city", "days"],
    
    async run(req, res) {
        try {
            const { city, days = 7 } = req.query;
            
            // Your implementation here
            const forecast = await WeatherService.getForecast(city, days);
            
            res.json({
                success: true,
                data: forecast
            });
        } catch (error) {
            res.status(500).json({
                success: false,
                error: error.message
            });
        }
    }
}
  1. The endpoint will be automatically available at:
  • GET /api/weather/forecast?city=London&days=5

API Response Format

All successful responses follow this format:

{
    "statusCode": 200,
    "success": true,
    "data": {
        "response": "Your data here"
    },
    "timestamp": "2023-01-01T00:00:00.000Z",
    "attribution": "@synshin9"
}

Error responses:

{
    "statusCode": 400,
    "success": false,
    "error": "Error message description"
}

Error Handling

The API includes comprehensive error handling:

  • 400 Bad Request: Invalid parameters
  • 404 Not Found: Endpoint not found
  • 500 Internal Server Error: Server-side errors

Custom error pages are served for web requests.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Support

Acknowledgments

  • Built with Express.js
  • Styled with Tailwind CSS
  • Icons from Material Icons
  • Fonts from Google Fonts

InuSoft API β€’ Modern REST API with Auto-Loading Endpoints

About

With Base @synshin9

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages