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.
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.
- π 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
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
| 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 |
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
});
}
}
}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
});
}
}
}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
- Clone the repository
git clone https://github.com/synshin9/Restfull-Api.git cd Restfull-Api - Install dependencies
npm install
- Start the development server
npm run dev
- Access the API
- API Documentation: http://localhost:3000
- API Endpoints: http://localhost:3000/api/ai/gpt
- OpenAPI Spec: http://localhost:3000/api/openapi.json
The project includes vercel.json for zero-config deployment:
npm i -g vercel
vercelEnvironment Variables
Create a .env file for environment-specific configurations:
PORT=3000
NODE_ENV=productionAdding New Endpoints
- 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
});
}
}
}- The endpoint will be automatically available at:
- GET /api/weather/forecast?city=London&days=5
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"
}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.
- Fork the repository
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add some amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- π§ Email: admin@inusoft.xyz
- π¬ Telegram: t.me/synshin9
- 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