1.0.4 • Published 4 months ago

alien-node-api-utils v1.0.4

Weekly downloads
189
License
MIT
Repository
github
Last release
4 months ago

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, next) {
  userModel.getUsers().
    then(apiUtils.jsonResponseSuccess(req, res)).
    catch(apiUtils.jsonResponseError(req, res, next));
};

module.exports = getUsers;
1.0.4

4 months ago

1.0.3

8 months ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.6

8 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago