npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

api-rest-generator

v1.1.0

Published

Generate a CRUD & an API REST automatically with only configure a sequelize model

Readme

API REST GENERATOR

Know can you create an API REST with only 2 code lines? It's posible thanks to this package! TRY NOW.

INSTALLATION


npm install api-rest-generator

o

yarn add api-rest-generator

REQUISITES

  • Sequelize
  • Express

FEATURES

  • Create multiple CRUD in seconds with the pagination solved.
  • You can disable pagination.
  • Create an API REST automatically.
  • Data validators (Sequelize).
  • Customizable (paths & methods).
  • Implement your middlewares on each path or method.
  • Not necessarily should create a CRUD. You define which methods to use and which not. (onlyMethods & exceptMethods).

EXAMPLE

//api-rest-generator
const ApiRestGenerator = require('api-rest-generator');

//express
const express = require('express');
const server = express();
const port = 3000;

//import your Sequelize models
const { User, Post, Comment } = require('./models');

//configure your resources.
const resources = [
    User,
    {
        model: Post,
        path: 'articles',
        indexConfig:{
            include: 'comments'
        }
    },
    Comment
]

//package options
const config = {
    basePath: '/api',
    middlewares: [],

    /*
        for example:
            middleware: [foo(), bar()]

        result:
            router.use(middleware[0]);
            router.use(middleware[1]);
    */
}

const apigen = new ApiRestGenerator(resources, config);

//start server
server.listen(port, () => {
        
        //black magic implementation
        server.use(
            apigen.config.basePath,
            apigen.router()
        );
        console.log(`Server is running at http://localhost:${port}`);
    })

Now, go to http://localhost:3000/api/users ;)

GENERATED METHODS

  • index: List your records.
  • show: For find by primaryKey.
  • create: Insert new record.
  • update: Update your record by primaryKey.
  • destroy: Detroy your record by primaryKey.

ENDPOINTS

  • GET /${basePath}/${recordPath} #list
  • GET /${basePath}/${recordPath}/:pk #show
  • POST /${basePath}/${recordPath} #create
  • PUT /${basePath}/${recordPath}/:pk #update
  • DELETE /${basePath}/${recordPath}/:pk #destroy

CONFIGURE YOUR RESOURCES


[
    {
        model: ModelName,
        path: 'model-name',

        withPagination: true,

        indexConfig: (req) => {} || {},
        /*
            Example for filters:

            indexConfig: (req) => {
                const {status} = req.query;

                if(status) => {
                    return {
                        where: { status }
                    }
                }
            }

        */
        showConfig: (req) => {} || {},
        updateConfig: (req) => {} || {},
        destroyConfig: (req) => {} || {},

        beforeCreate: (model) => model || null,
        beforeUpdate: (model) => model || null,
        beforeDestroy: (model) => model || null,

        afterCreate: (model) => model || null,
        afterUpdate: (model) => model || null,
        afterDestroy: (model) => model || null,

        middlewares: [],
        /*
            for example:
                middleware: [foo(), bar()]

            result:
                router.use(`${basePath}/${path}`,middleware[0]);
                router.use(`${basePath}/${path}`,middleware[1]);
        */

        // middewares array
        allProtection: [] || "function",
        indexProtection: [] || "function", 
        showProtection: [] || "function",
        createProtection: [] || "function",
        updateProtection: [] || "function",
        destroyProtection: [] || "function",
        /*
            route.get('/path', methodProtection, (req,res) => ...)
        */

        onlyMethods: [], //index, show, create, update, destroy
        exceptMethods: [], //index, show, create, update, destroy
    }
]

PAGINATION

We use the sequelize-paginate package to resolve the paginations.