Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/huangang/fastify-call

Fastify plugin to call self method.
https://github.com/huangang/fastify-call

fastify fastify-call fastify-plugin

Last synced: about 2 months ago
JSON representation

Fastify plugin to call self method.

Awesome Lists containing this project

README

        

# fastify-call

Fastify plugin to call self method.

[![Build Status](https://travis-ci.org/huangang/fastify-call.svg?branch=master)](https://travis-ci.org/huangang/fastify-call)
[![NPM version](https://img.shields.io/npm/v/fastify-call.svg?style=flat)](https://www.npmjs.com/package/fastify-call)
## Install
```
npm i fastify-call --save
```
## Usage

```js
'use strict'

const fastify = require('fastify')()

fastify.register(require('fastify-call'))

fastify.get('/t1', function (request, reply) {
reply.send({ 'hello': 't1' })
})

fastify.get('/t2', function (request, reply) {
return fastify.call('t1').then((data) => {
data.world = 't2'
return reply.send(data)
})
})

fastify.get('/t3', function (request, reply) {
return fastify.call.post('t1', { a: 1 }).then((data) => {
data.world = 't3'
return reply.send(data)
})
})

fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
```