Giter VIP home page Giter VIP logo

expressa's Introduction

CircleCI

data-driven extendable API middleware for Node.js/Express

Expressa makes it easy to create basic APIs by using JSON schema:

  • django-like admin interface for creating collection-REST endpoints and managing permissions
  • collection schema's can be edited and added through the admin interface
  • re-use collection schema's in your frontend to generate forms
  • easily extendable so you can add complex features as well
  • define collections as JSON schema instead of custom code
  • per-collection database storage: MongoDB, PostgreSQL, or JSON-files (useful for version control)

Best of all: it's just middleware, not a framework

  • mix-and-mash: easily throw in other express middleware and endpoints
  • decorate expressa-endpoints: add event listeners which stop/modify requests (responses)

Getting Started

It's very easy to install expressa in your project directory:

mkdir myapp
cd myapp
npm init
npm install expressa expressa-admin express

Create a file app.js with the following code (or just copy the middle 3 lines into your existing express app)

var express = require('express');
var app = express();

var expressa = require('expressa');
app.use('/api', expressa.api());            // optionally pass in settings
app.use('/admin', expressa.admin({ apiurl: '/api/' }));

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

Now start the server by running node --use-strict app.js and navigate your browser to http://localhost:3000/admin/

API endpoints

Once you add a collections in the admin interface, every collection will have the following endpoints:

method endpoint description
POST /user/login expects JSON in the message body. e.g. `{"email": "[email protected]", password: ""}
GET /:collection get an array of all documents in a collection
GET /:collection/:id get a specific document
GET /:collection/?query={..} get an array of documents matching the mongo query. For pagination append &skip=0&offset=0&limit=6
GET /:collection/?query={..}&limit=10&page=1&orderby=["meta.created"] same as previous, but with pagination support
GET /:collection/?query={..}&limit=10&offset=10 same as previous, but with finergrained output control
GET /:collection/?fieldname=value get an array of documents matching with the specified values. See node-mongo-querystring for details.
GET /:collection/schema get the collection schema
POST /:collection/ create a new document, the message body should be the JSON document
PUT /:collection/:id replace the document with id. The message body should be the JSON document. If the _id in document is different (the old document _id is deleted and a new one with id is created.)
POST /:collection/:id/update modify the document with id using a mongo update query. The message body should be the update query
DELETE /:collection/:id delete the document

Supported Data: Only standard JSON (strings, numbers, booleans, null) is supported. Dates can be stored as strings using ISO 8601

Each object will contain this meta property which has autogenerated fields shared across all collection types:

  "meta": {
    "created": "2016-05-16T23:56:11.615Z",
    "updated": "2016-05-16T23:56:28.262Z",
    "owner": "56cb5df7f56ef0b92f7b984b"
  },

Documentation

Admin UI Examples/Screenshots

Expressa ecosystem

  • expressa-folder easily extend expressa collections with ORM-ish js-code (get.js/post.js/functions.js/etc) & setup sub-endpoints
  • expressa-swagger middleware to generate online api documentation
  • expressa-client middleware to generate browser REST-client (+nodejs client)
  • expressa-cli commandline interface for expressa

Roadmap

  • Automatic GraphQL Support
  • JWT token expiration
  • Support cookie based authentication as well
  • File uploads

Alternatives

Expressa is not primarily built for simple blog websites or mostly static content websites. For those a cms like Keystone.js and enduro.js could work or maybe you could build you site with a static site generator like Hugo. For database-driven websites that need a strong CRUD backend where you want a clear separation between the frontend and backend, expressa.js is a great choice.

Changelog

  • Due to many changes, please test your site thoroughly after updating to 0.4 before releasing to production.
version important changes
0.4.1 db.create (postgres) now returns the id instead of the full document.
0.4.0 Pagination now starts with page 1. Delete requests can no longer bypass rejections by listeners. Updated permission error codes/messages. Error responses now always json (with an "error" field explaining) PUT /collection/:id response changed to match POST /collection
0.3.3 Fixes security vulnerability with the "edit own" permission and the :collection/:id/update endpoint. Update immediately.
0.3.2 Pagination is now supported by specifying the "page" and "limit"
0.3.1 Makes "development" the default settings file instead of "production". Use NODE_ENV environmental variable to change this. To quickly migrate, just rename your settings file to "development".

Inspired by

expressa's People

Contributors

brismuth avatar coderofsalvation avatar laksh95 avatar thomas4019 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.