0.1.0 • Published 9 years ago

express-rest-api v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

Express REST API

Install from NPM

npm install express-rest-api

Express REST API is an express middleware package. It provides a collection of response methods for sending standardized REST responses. It also normalizes property casing biased on what the client desires. It also exposes sort, limit, and skip on the request object.

An example of getting an item

var express        = require('express');
var bodyParser     = require('body-parser');
var expressRestApi = require('express-rest-api');


var app = express();

app.use(bodyParser.json());
app.use(expressRestApi());

// getting and sending an existing item
app.get('item/:id', (req, res, next) => {
  req.db.collection('items').findById(req.params.id, (err, item) => {
    if (err) { return next(err); }
    if (!item) { return res.status(404).end(); }

    // sends the item body, and a location header.
    res.sendFound(item);
  });
});