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.
Follow these steps to generate your API:
The API Generator supports schemas for a single table (SQL, PostgreSQL), collection (Firebase), or model (Prisma). Below are the supported formats and examples:
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 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 format for collections, suitable for Firebase Firestore or generic structures.
{
"collections": {
"products": {
"fields": {
"id": "string",
"name": "string",
"price": "number",
"createdAt": "timestamp"
}
}
}
}
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 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
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.
Below are snippets of generated code for the `products` table/collection/model using different languages and databases.
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
}
?>
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
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
For further assistance, contact support or visit the main app page.