# restify-await-promise

> Restify Plugin to support promises and async/await

Latest version **2.2.0** (published 2019-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install restify-await-promise
pnpm add restify-await-promise
yarn add restify-await-promise
bun add restify-await-promise
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2019-08-12 |
| First published | 2017-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ConnectedYard, Inc. |
| Maintainers | corim707 |
| Keywords | restify, promise, async-await |

## Links

- npm: https://www.npmjs.com/package/restify-await-promise
- Repository: https://github.com/PhinCo/restify-await-promise
- Homepage: https://github.com/PhinCo/restify-await-promise#readme
- Issues: https://github.com/PhinCo/restify-await-promise/issues
- npm.io page: https://npm.io/package/restify-await-promise

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 2.2.0 (latest) — 2019-08-12
- 2.1.0 — 2018-09-06
- 2.0.2 — 2018-08-19
- 2.0.1 — 2018-08-19
- 2.0.0 — 2018-08-19
- 1.0.2 — 2017-09-07
- 1.0.1 — 2017-09-07
- 1.0.0 — 2017-09-07

## README

# restify-await-promise

[![Build Status](https://travis-ci.org/PhinCo/restify-await-promise.svg)](https://travis-ci.org/PhinCo/restify-await-promise)
[![dependency Status](https://david-dm.org/PhinCo/restify-await-promise/status.svg)](https://david-dm.org/PhinCo/restify-await-promise#info=dependencies)
[![peerDependency Status](https://david-dm.org/PhinCo/restify-await-promise/peer-status.svg)](https://david-dm.org/PhinCo/restify-await-promise#info=peerDependencies)
[![devDependency Status](https://david-dm.org/PhinCo/restify-await-promise/dev-status.svg)](https://david-dm.org/PhinCo/restify-await-promise#info=devDependencies)

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+ <br>
  <strong>NOTE:</strong> Does not support Restify 7+ conditionalRouteHandler

# Usage

```javascript
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
```bash
$ npm install --save restify-await-promise
```

## Bugs

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

---
_Source: https://npm.io/package/restify-await-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
