New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

apiato

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apiato

An amazing and easy to use CRUD API-REST/SOCKETIO constructors for API with mongoDB(mongoose) and SQL(sequelize)

latest
Source
npmnpm
Version
3.1.2
Version published
Weekly downloads
40
-66.94%
Maintainers
1
Weekly downloads
 
Created
Source

Apiato.js

A powerful and flexible API library for Node.js that supports both SQL (Sequelize) and NoSQL (Mongoose) databases, with REST and Socket.IO implementations.

Features

  • 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)

Installation

bun install apiato

Examples

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)

Running the Examples

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

Example Ports

  • Sequelize REST API: http://localhost:3000
  • Mongoose REST API: http://localhost:3001
  • Mongoose Socket.IO: http://localhost:3002
  • Sequelize Socket.IO: http://localhost:3003

Usage

REST API with Sequelize

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));

REST API with Mongoose

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));

Socket.IO with Sequelize/Mongoose

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: "john@example.com",
        age: 30
    },
    responseType: "private" // or "broadcast" or "room"
}));

API Documentation

REST API Endpoints

  • POST /: Create a new record
  • GET /: Get all records (with pagination, sorting, filtering)
  • GET /:id: Get a record by ID
  • PUT /:id: Update a record by ID
  • DELETE /:id: Delete a record by ID

Socket.IO Events

  • create: Create a new record
  • getMany: Get all records
  • getOneById: Get a record by ID
  • updateById: Update a record by ID
  • deleteById: Delete a record by ID

Query Parameters (REST API)

  • where: Filter records by field values
  • like: Filter records using partial matches
  • select: Select specific fields
  • paginate: Paginate results (page, limit)
  • sort: Sort results by fields
  • populate/include: Include related records

Socket.IO Request Format

{
    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
}

License

MIT

Keywords

CRUD

FAQs

Package last updated on 22 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts