Git Product home page Git Product logo

neatsio's Introduction

Neatsio REST

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
  • Hooks
  • Customs routes
  • Written in typescript

Getting Started

1. Install Neatsio REST

$ npm install --save @owliehq/neatsio
$ 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('@owliehq/neatsio')
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.registerModel(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

neatsio's People

Contributors

uminily avatar matejicekme avatar semantic-release-bot avatar barthelemy1 avatar ortes avatar steakdeniche avatar ericowlie avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.