Skip to content

huangang/fastify-call

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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