Skip to content

Initial Release: express-api-generator v1.0.1 🚀

Latest

Choose a tag to compare

@bhar2254 bhar2254 released this 22 Nov 20:18
· 6 commits to main since this release

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 initializeAPI function.
    • 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 initializeAPI function.
    • 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',
      });

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 the checkScope middleware to protect routes and ensure only authorized users can access them.