Skip to content

jcald1/alien-node-api-utils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alien-node-api-utils

Helper functions for API handling on NodeJS. The functions are pure and curried with Ramda.

Build Status Coverage Status npm version Dependency Status

Install

$ npm install alien-node-api-utils --save

Run the specs

$ npm test

Usage

// Example API route such as '/users' which could reasonably leverage a 
// 'user' model which would return a promise or catch with an error object.

// The error object passed in the catch should include a 'statusCode' property
// that is specific to the respective error. If it does not, the api utils 
// will default to 500.

// Note: Because the util functions are curried, we can keep them pure and by 
// invoking with req and res, as shown below.

var apiUtils  = require('alien-node-api-utils'),
    userModel = require('./models/user');

function getUsers(req, res) {
  userModel.getUsers().
    then(apiUtils.jsonResponseSuccess(req, res)).
    catch(apiUtils.jsonResponseError(req, res));
};

module.exports = getUsers;

Changelog

0.1.1
  • set node version to 6 in travis.yml for es6 support
0.1.2
  • add support for missing req.flash
0.1.3
  • fix circular json in response
0.1.4
  • add fix for res.headerssent
  • serialize errors in the response so that properties like 'stack' are included in the response

About

Helper functions for API handling on NodeJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%