UNPKG

aj-rest-api-generator

Version:

šŸ”„ A powerful and interactive CLI tool to scaffold REST API boilerplates in seconds.

195 lines (145 loc) • 5.79 kB
# AJ REST API Generator šŸš€ [![npm version](https://img.shields.io/npm/v/aj-rest-api-generator)](https://npmjs.com/package/aj-rest-api-generator) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js CI](https://github.com/Aj3322/aj-rest-api-generator/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/Aj3322/aj-rest-api-generator/actions/workflows/npm-publish.yml) A CLI tool to instantly scaffold production-ready Node.js REST APIs with either CommonJS or ES Modules support. <img src="https://github.com/user-attachments/assets/3cda5952-8970-43fa-97b9-34a968d2e5e3" /> ## Features ✨ - āš”ļø Instant REST API scaffolding - šŸ”„ Supports both CommonJS and ES Modules - šŸ“ Organized folder structure - šŸ” Built-in best practices - šŸ› ļø Configurable options - šŸ“¦ Ready-to-use with Express.js ## Installation šŸ“¦ ### Global Installation (Recommended) ```bash npm install -g aj-rest-api-generator ``` ### Local Installation ```bash npm install aj-rest-api-generator --save-dev ``` ## Usage šŸš€ ### Interactive Mode ```bash aj create ``` ### With ES Modules ```bash aj create rest --name my-api --module ``` ### With CommonJS (default) ```bash aj create rest --name my-api --commonjs ``` ## Options āš™ļø | Option | Description | Default | |-----------------------|--------------------------------------------------|-------------| | `-n, --name <name>` | Set project name | `rest-api` | | `--module` | Use ES Modules format | `false` | | `--commonjs` | Use CommonJS format (default) | `true` | | `-f, --force` | Overwrite existing directory without prompting | `false` | | `-y, --yes` | Skip all prompts using default values | `false` | | `-v, --version` | Show package version | - | | `-h, --help` | Display help information | - | ### Behavior Notes: - When neither `--module` nor `--commonjs` is specified: - In interactive mode: Prompts for selection - With `--yes`: Defaults to CommonJS - `--force` will delete existing directories without confirmation - `--yes` will use these defaults: - Project name: `rest-api` - Module system: CommonJS - No directory overwriting (unless combined with `--force`) ## Project Structure šŸ“‚ Generated projects include: ``` project-root/ |── src/ | ā”œā”€ā”€ config/ # Configuration files | ā”œā”€ā”€ controllers/ # Route controllers | ā”œā”€ā”€ models/ # Database models | ā”œā”€ā”€ routes/ # Route definitions | ā”œā”€ā”€ middlewares/ # Custom express middlewares | ā”œā”€ā”€ services/ # Business logic services | ā”œā”€ā”€ utils/ # Utility classes and functions | ā”œā”€ā”€ validations/ # Request validation schemas | └── constants/ # Constants definitions |── tests/ # Test files |── docs/ # API documentation files |── logs/ # Log files |── public/ # Public assets |── uploads/ # File uploads |── .env.example # Example environment variables ā”œā”€ā”€ .env # Environment variables ā”œā”€ā”€ .gitignore # Git ignore file ā”œā”€ā”€ .eslintrc.js # ESLint configuration └── .prettierrc # Prettier configuration ``` #Example Endpoint --- ### 🩺 Health Check | Method | URL | Uses | |--------|-----|------| | `GET` | `/api/health` | Check if the server is alive | --- ### šŸ‘„ User Management | Method | URL | Uses | |--------|-----|------| | `POST` | `/api/users` | Create user | | `GET` | `/api/users` | List all users | | `GET` | `/api/users/:id` | Get user by ID | | `PUT` | `/api/users/:id` | Update user | | `DELETE` | `/api/users/:id` | Delete user | --- ### šŸ” Authentication | Method | URL | Uses | |--------|-----|------| | `POST` | `/api/auth/register` | User registration | | `POST` | `/api/auth/login` | User login | | `POST` | `/api/auth/refresh` | Refresh token | | `POST` | `/api/auth/logout` | User logout | --- ### šŸ“Š Metrics | Method | URL | Uses | |--------|-----|------| | `GET` | `/api/metrics` | System metrics | | `GET` | `/api/metrics/requests` | Request statistics | --- ### šŸ“š Documentation | Method | URL | Uses | |--------|-----|------| | `GET` | `/api/docs` | API documentation (Swagger/OpenAPI) | | `GET` | `/api/docs/json` | OpenAPI spec (JSON) | | `GET` | `/api/docs/yaml` | OpenAPI spec (YAML) | --- ## Development šŸ› ļø 1. Clone the repo: ```bash git clone https://github.com/yourusername/aj-rest-api-generator.git ``` 2. Install dependencies: ```bash npm install ``` 3. Link for local development: ```bash npm link ``` 4. Test your changes: ```bash npm test ``` ## Contributing šŸ¤ Contributions are welcome! Please follow these steps: 1. Fork the project 2. Create your feature branch (`git checkout -b feature/AmazingFeature`) 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) 4. Push to the branch (`git push origin feature/AmazingFeature`) 5. Open a Pull Request ## License šŸ“„ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ## Support šŸ’– If you find this project useful, please consider starring ⭐ the repository or buying me a coffee ā˜•: [![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/yourusername)