API Generator Documentation

The API Generator is a powerful tool that creates CRUD (Create, Read, Update, Delete) APIs for a single table, collection, or model based on your schema. Upload a schema file, select the programming language and target database, and generate API code instantly. The generated code can be viewed, downloaded, and integrated into your applications.

How to Use the API Generator

Follow these steps to generate your API:

  1. Upload Schema: Provide a schema file for a single table/collection/model in a supported format (SQL, JSON, Prisma, or YAML).
  2. Select Language: Choose the programming language for the API code (PHP, React, or JavaScript).
  3. Select Target Database: Specify the database for which the API code should be generated (MySQL, MariaDB, PostgreSQL, Prisma, or Firebase).
  4. Generate Code: Click the "Generate API" button to create the code.
  5. View and Download: Review the generated code in the browser and download individual files or all files as a single archive.

Supported Schema Formats

The API Generator supports schemas for a single table (SQL, PostgreSQL), collection (Firebase), or model (Prisma). Below are the supported formats and examples:

SQL Schema (MySQL/MariaDB)

Standard SQL schema for MySQL or MariaDB with a CREATE TABLE statement.

CREATE TABLE products (
    `id` INT PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(255),
    `price` DECIMAL(10,2),
    `createdAt` DATETIME DEFAULT CURRENT_TIMESTAMP
);

SQL Schema (PostgreSQL)

SQL schema for PostgreSQL using SERIAL for auto-incrementing IDs.

CREATE TABLE products (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255),
    price NUMERIC(10,2),
    createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

JSON Schema (Firebase-like)

JSON format for collections, suitable for Firebase Firestore or generic structures.

{
    "collections": {
        "products": {
            "fields": {
                "id": "string",
                "name": "string",
                "price": "number",
                "createdAt": "timestamp"
            }
        }
    }
}

Prisma Schema

Prisma schema with a model definition, used for Prisma Client.

model products {
    id        Int      @id @default(autoincrement())
    name      String
    price     Float
    createdAt DateTime @default(now())
}

YAML Schema

YAML format with a tables key for table structures.

tables:
    products:
        columns:
            - name: id
              type: integer
            - name: name
              type: string
            - name: price
              type: float
            - name: createdAt
              type: timestamp

Supported Languages and Databases

The API Generator supports multiple programming languages and target databases. You can generate code for a table/collection/model in any supported database, regardless of the schema format.

Languages

Target Databases

Example Generated Code

Below are snippets of generated code for the `products` table/collection/model using different languages and databases.

PHP (MySQL)

Generates a `ProductsModel` class with PDO-based CRUD methods.

db = $db;
    }

    public function create(array $data) {
        $sql = "INSERT INTO `products` (`id`, `name`, `price`, `createdAt`) VALUES (?, ?, ?, ?)";
        $stmt = $this->db->getPdo()->prepare($sql);
        $stmt->execute(array_values($data));
        return $this->db->getPdo()->lastInsertId();
    }
    // ... other CRUD methods
}
?>

React (Prisma)

Generates a `server.js` with Prisma Client for the backend.

require('dotenv').config();
const express = require('express');
const { PrismaClient } = require('@prisma/client');
const app = express();
app.use(express.json());

const prisma = new PrismaClient();

app.route('/api/products')
  .post(async (req, res) => {
    try {
      const data = req.body;
      const result = await prisma.products.create({
        data: {
          name: data.name,
          price: parseFloat(data.price),
          createdAt: new Date(data.createdAt || Date.now())
        }
      });
      res.status(201).json({ status: 'success', message: 'Created successfully', data: { id: result.id } });
    } catch (err) {
      res.status(400).json({ status: 'error', message: err.message, data: null });
    }
  });
// ... other routes

JavaScript (Firebase)

Generates a `server.js` with Firestore SDK for NoSQL operations.

require('dotenv').config();
const express = require('express');
const { Firestore } = require('@google-cloud/firestore');
const app = express();
app.use(express.json());

const firestore = new Firestore({ projectId: process.env.FIREBASE_PROJECT_ID });

app.route('/api/products')
  .post(async (req, res) => {
    try {
      const data = req.body;
      const docRef = await firestore.collection('products').add(data);
      res.status(201).json({ status: 'success', message: 'Created successfully', data: { id: docRef.id } });
    } catch (err) {
      res.status(400).json({ status: 'error', message: err.message, data: null });
    }
  });
// ... other routes

Troubleshooting

Additional Notes

For further assistance, contact support or visit the main app page.