Fastify Request(請求)

2020-02-06 15:41 更新

Request

處理函數(shù)的第一個參數(shù)是 Request.Request 是 Fastify 的核心對象,包含了一下的字段:

  • query - 解析后的 querystring
  • body - 消息主體
  • params - URL 參數(shù)
  • headers - headers
  • raw - Node 原生的 HTTP 請求 (可以用別名 req)
  • id - 請求 id
  • log - 請求的日志實例
  • ip - 請求方的 ip 地址
  • ips - x-forwarder-for header 中保存的請求源 ip 數(shù)組 (僅當 trustProxy 開啟時有效)
  • hostname - 請求方的主機名
fastify.post('/:params', options, function (request, reply) {
  console.log(request.body)
  console.log(request.query)
  console.log(request.params)
  console.log(request.headers)
  console.log(request.raw)
  console.log(request.id)
  console.log(request.ip)
  console.log(request.ips)
  console.log(request.hostname)
  request.log.info('some info')
})


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號