https://github.com/bendrucker/hapi-as-promised
A hapi plugin that allows you to reply with promises in your request handlers
https://github.com/bendrucker/hapi-as-promised
Last synced: over 1 year ago
JSON representation
A hapi plugin that allows you to reply with promises in your request handlers
- Host: GitHub
- URL: https://github.com/bendrucker/hapi-as-promised
- Owner: bendrucker
- License: mit
- Created: 2014-02-04T17:12:44.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2021-01-26T04:22:48.000Z (over 5 years ago)
- Last Synced: 2025-04-10T08:14:01.400Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 15
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
hapi-as-promised [](https://travis-ci.org/bendrucker/hapi-as-promised) [](http://badge.fury.io/js/hapi-as-promised)
============
Handle promises passed to `reply` with a promise in Hapi 6 or 7. Hapi 8 adds native [promise support to `reply`](http://hapijs.com/api#replyerr-result), inspired by hapi-as-promised.
## Usage
```javascript
server.route({
method: 'GET'
path: '/',
handler: function (request, reply) {
reply(promise);
}
});
```
The plugin will automatically intercept all replies that are **thenables** (have a property `then` that is a function) and resolve them. You can still chain methods to your reply like `code`. Only the reply body itself is modified. Error behavior is unchanged. A rejection with `err.isBoom === true` will be serialized and sent to the client, while all others will be transformed into 500s.