A powerful and flexible API library for Node.js that supports both SQL (Sequelize) and NoSQL (Mongoose) databases, with REST and Socket.IO implementations.
- Support for both SQL (Sequelize) and NoSQL (Mongoose) databases
- REST API implementation
- Socket.IO implementation
- TypeScript support
- Validation
- Pagination
- Sorting
- Filtering
- Population/Include relations
- Room-based communication (Socket.IO)
- Broadcasting (Socket.IO)
bun install apiato
This repository includes four example implementations:
- REST API with Sequelize (SQLite)
- REST API with Mongoose (MongoDB)
- Socket.IO with Sequelize (SQLite)
- Socket.IO with Mongoose (MongoDB)
Each example is in its own directory under examples/
. To run an example:
- Navigate to the example directory:
cd examples/[example-name]
- Install dependencies:
bun install
- Start the development server:
bun run dev
- Sequelize REST API: http://localhost:3000
- Mongoose REST API: http://localhost:3001
- Mongoose Socket.IO: http://localhost:3002
- Sequelize Socket.IO: http://localhost:3003
import { ApiatoSQL } from 'apiato/typescript';
import User from './models/User';
const apiato = new ApiatoSQL();
// Create routes
router.post('/', apiato.createOne(User));
router.get('/', apiato.getMany(User));
router.get('/:id', apiato.getOneById(User));
router.put('/:id', apiato.updateById(User));
router.delete('/:id', apiato.findIdAndDelete(User));
import { ApiatoNoSQL } from 'apiato/typescript';
import User from './models/User';
const apiato = new ApiatoNoSQL();
// Create routes
router.post('/', apiato.createOne(User));
router.get('/', apiato.getMany(User));
router.get('/:id', apiato.getOneById(User));
router.put('/:id', apiato.updateById(User));
router.delete('/:id', apiato.findIdAndDelete(User));
import { ApiatoSocket } from 'apiato/typescript';
import { Server } from 'socket.io';
import User from './models/User';
const io = new Server(httpServer);
const userSocket = new ApiatoSocket(io, User);
// Available events:
// - create
// - getMany
// - getOneById
// - updateById
// - deleteById
// Example client usage:
socket.emit('create', JSON.stringify({
body: {
name: "John Doe",
email: "[email protected]",
age: 30
},
responseType: "private" // or "broadcast" or "room"
}));
POST /
: Create a new recordGET /
: Get all records (with pagination, sorting, filtering)GET /:id
: Get a record by IDPUT /:id
: Update a record by IDDELETE /:id
: Delete a record by ID
create
: Create a new recordgetMany
: Get all recordsgetOneById
: Get a record by IDupdateById
: Update a record by IDdeleteById
: Delete a record by ID
where
: Filter records by field valueslike
: Filter records using partial matchesselect
: Select specific fieldspaginate
: Paginate results (page, limit)sort
: Sort results by fieldspopulate/include
: Include related records
{
body?: any; // Data for create/update operations
id?: number | string; // Record ID for single-record operations
query?: { // Query parameters
where?: any; // Filter conditions
attributes?: string[]; // Fields to select (Sequelize)
select?: any; // Fields to select (Mongoose)
include?: any[]; // Relations to include
sort?: any; // Sort conditions
paginate?: { // Pagination
page: number;
limit: number;
}
};
responseType?: 'private' | 'broadcast' | 'room'; // Response type
room?: string; // Room name for room-based responses
tag?: string; // Custom tag for response tracking
}
MIT