Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restify-await-promise

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-await-promise

Restify Plugin to support promises and async/await

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

restify-await-promise

Build Status dependency Status peerDependency Status devDependency Status

Converts restify routes to support async/await and returned promises. Works with Restify 4.x through 6.x. May work with Restify 7+.

#Supported Restify Versions

  • Fully Supported
    • 4.x to 5.x
  • Probably Works
    • 6.x
  • Partially Compatible
    • 7.x+
      NOTE: Does not support Restify 7+ conditionalRouteHandler

Usage

const restify = require('restify');
const restifyPromise = require('restify-await-promise');

const server = restify.createServer({
  name: 'myapp',
  version: '1.0.0'
});

//Allows you to manipulate the errors before restify does its work
const alwaysBlameTheUserErrorTransformer = {
	transform: function( exceptionThrownByRoute ){
		//Always blame the user
		exceptionThrownByRoute.statusCode = 400; 
		return exceptionThrownByRoute;
	}
}

const options = {
	logger: yourLogger,                                  //Optional: Will automatically log exceptions	
	errorTransformer: alwaysBlameTheUserErrorTransformer //Optional: Lets you add status codes 
};

restifyPromise.install( server, options ); // Options is not required

//Async function, automatically calls send with the returned object and next
server.get('/lookup/:name', async function (req) {
	return await SomePromise.work( req.parms.name );
});

//Promise function
server.get('/echo/:name', function (req) {
	const params = req.params; 
	return Promise.resolve( { params } );
});

//Existing restify method
server.get('/echo2/:name', function (req, res, next) {
	  res.send(req.params);
	  next();
});

server.listen(8080, function () {
	  console.log('%s listening at %s', server.name, server.url);
});

Installation

$ npm install --save restify-await-promise

Bugs

See https://github.com/PhinCo/restify-await-promise/issues.

Keywords

FAQs

Package last updated on 12 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc