npm.io
2.0.2 • Published 6 years ago

fastify-call

Licence
MIT
Version
2.0.2
Deps
1
Size
15 kB
Vulns
0
Weekly
0
Stars
3

fastify-call

Fastify plugin to call self method.

Build Status NPM version

Install

npm i fastify-call --save

Usage

'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}`)
})

Keywords