Repository navigation
Releases
Releases · bhar2254/express-api-generator
Initial Release: express-api-generator v1.0.1 🚀
Features:
- Dynamic RESTful API Routes: Automatically generates CRUD routes (
GET,POST,PUT,DELETE) for any database table. Routes are accessible via/api/v1/:table, and individual records can be accessed via/api/v1/:table/:ident. - Database Configuration: Supports both MySQL and SQLite databases. The database connection is configurable in the
initializeAPIfunction.- MySQL: Full support for MySQL database connections with options for host, user, password, and database name.
- SQLite: SQLite support for storing API keys and their associated scopes in a local database, allowing for simpler setup without requiring modifications to the user's existing database schema.
- API Key Authentication: Secure your API routes with API key authentication. The API keys can be stored in an internal SQLite database to avoid exposing sensitive keys within the user’s primary database.
- Scopes-Based Authorization: Introduced scope-based access control. Users can restrict access to certain API routes based on the API key’s assigned scope (e.g.,
read,write,admin). - Automatic API Key Generation: Includes a route for generating new API keys and saving them into the local SQLite store, making it easy for users to integrate API key-based authentication without manual setup.
Configuration:
- Simple Setup: Users can configure the API routes and database options using the
initializeAPIfunction.- Example configuration for MySQL:
initializeAPI(app, { version: 'v1', database: { type: 'mysql', options: { host: 'localhost', user: 'your_user', password: 'your_password', database: 'your_db', } }, apiKeyStore: 'sqlite', // Option to store API keys in a separate SQLite DB });
- Example configuration for SQLite:
initializeAPI(app, { version: 'v1', database: { type: 'sqlite', options: { database: 'your_db.sqlite', } }, apiKeyStore: 'sqlite', });
- Example configuration for MySQL:
Usage:
-
Generated Routes:
GET /api/v1/:table: Fetch all records from a table.GET /api/v1/:table/:ident: Fetch a single record using either a GUID or a query key.POST /api/v1/:table: Insert a new record into the table.PUT /api/v1/:table/:ident: Update an existing record.DELETE /api/v1/:table/:ident: Delete a record from the table.
-
Scopes-Based Access:
Routes can be restricted by scope (e.g.,read,write). Use thecheckScopemiddleware to protect routes and ensure only authorized users can access them.