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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@neatsio/rest

v1.4.0

Published

[![Build Status](https://travis-ci.org/neatsio/rest.svg?branch=master)](https://travis-ci.org/neatsio/rest) [![Dependencies](https://david-dm.org/neatsio/rest.svg)](https://david-dm.org/neatsio/rest) [![Coverage Status](https://coveralls.io/repos/github/n

Downloads

5

Readme

Neatsio REST

Build Status Dependencies Coverage Status

When using Neatsio REST lib, you can create REST APIs in seconds. Built on top of ExpressJS, Neatsio REST removes your boilerplate work time. Focus on models and business logic, the lib generate automatically endpoints based on mongoose/sequelize schemas. Save your time and enjoy with your new REST routes.

This lib is opinionated, some features or development orientation are due to personal choices, but PR are welcome.

Features

  • CRUD endpoints generated from Mongoose (partially) or Sequelize schema
  • Support of query paramaters to handle filtering, pagination, sorting, and sub-populating
  • Handle express middlewares
  • [TODO] Options, options, options everywhere...
  • [TODO] Authorization & role by route-level or document-level
  • [TODO] Hooks
  • [TODO] Addition of routes based on generated ones
  • [TODO] Plugins?
  • Written in typescript
  • ...more to come

Getting Started

1. Install Neatsio REST

$ npm install --save @neatsio/rest
$ npm install --save express body-parser sequelize

[OPTIONAL FOR TESTING]
$ npm install --save sqlite3

2. Basic usage (give it a try)

const express = require('express')
const bodyParser = require('body-parser')
const neatsioRest = require('@neatsio/rest')
const Sequelize = require('sequelize')

const sequelize = new Sequelize({
  dialect: 'sqlite',
  storage: __dirname + '/database.sqlite',
  logging: false
})

// Init your sequelize models
class User extends Sequelize.Model {}
User.init(
  {
    firstname: { type: Sequelize.DataTypes.STRING, allowNull: false },
    lastname: { type: Sequelize.DataTypes.STRING, allowNull: false },
    email: { type: Sequelize.DataTypes.STRING, allowNull: false }
  },
  {
    sequelize,
    modelName: 'user'
  }
)

const app = express()

// Register your model
neatsioRest.registryModel(User)

// Bodyparsing is needed to handle payloads on POST / PUT routes
app.use(bodyParser.json())

// Neatsio brings to you an express router
app.use('/api', neatsioRest.routes)

sequelize.authenticate().then(() => {
  User.sync().then(() => {
    app.listen(3000, () => {
      console.log('Neatsio REST API started on port 3000!')
    })
  })
})

Start server

$ node app.js

Make calls to your API

# Get all users (empty)
GET http://localhost:3000/api/users

# Create an user
POST http://localhost:3000/api/users

# Get user by ID
GET http://localhost:3000/api/users/1

# Get user's lastname by ID
GET http://localhost:3000/api/users/1?$select='lastname'

# Get users lastname order by email DESC
GET http://localhost:3000/api/users?$select='lastname'&sort='-email'

# Get users populated with embed models with conditions
GET http://localhost:3000/api/users?$populate='posts.comments'&$conditions={"$or":[{"$email:"[email protected]"},{"id":2}]}

# Update user
PUT http://localhost:3000/api/users/1

# Delete user
DELETE http://localhost:3000/api/users/1

# Create in bulk
POST http://localhost:3000/api/users/bulk

# Update in bulk with conditions
PUT http://localhost:3000/api/users/bulk?$conditions={"active":false}

Getting Support

  • Check out GitHub issues opened, send us an mail
  • To file a bug: create a GitHub issue on this repo. Be sure to include details about how to replicate it.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

Copyright (c) 2019

Licensed under MIT