Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.85 KB

README.md

File metadata and controls

53 lines (35 loc) · 1.85 KB

Build Status

express-rest-resource

An express 4+ Router representing a RESTful resource as JSON.

Forked from https://github.com/adjohnson916/express-rest-resource

BYODB - Bring your own database! (see database dependency).

Originally written to help get prototype apps running anywhere quickly and hassle-free - a main reason why support for nedb's in-memory or file-based databases was built-in.

Provides standard RESTful routes, mapping to database calls:

GET     /       ->  list all
GET     /:id    ->  read one
POST    /       ->  insert
PUT     /:id    ->  update
DELETE  /:id    ->  remove

This router can be mounted at any path in your express app. Routes behave RESTfully - responding with meaningful HTTP status codes, validating accepts and content types, etc.

Database dependency

For modularity, a database implementation is not built-in. Instead, a database (or collection) must be injected as a dependency. Expects the injected database to implement a subset of the MongoDB API. Supported databases include: nedb, MongoDB.

Examples

var express = require('express');
var expressRestResource = require('express-rest-resource');
var nedb = require('nedb');

var app = express();

var personDb = new nedb();
var postDb = new nedb();

app.use('/api/person', expressRestResource({ db: personDb }));
app.use('/api/post', expressRestResource({ db: postDb }));

app.listen();

Now, a POST to http://localhost:3000/api/person with JSON body would create and persist a new person resource.