Fastify Request(請(qǐng)求)

2020-02-06 15:41 更新

Request

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

  • query - 解析后的 querystring
  • body - 消息主體
  • params - URL 參數(shù)
  • headers - headers
  • raw - Node 原生的 HTTP 請(qǐng)求 (可以用別名 req)
  • id - 請(qǐng)求 id
  • log - 請(qǐng)求的日志實(shí)例
  • ip - 請(qǐng)求方的 ip 地址
  • ips - x-forwarder-for header 中保存的請(qǐng)求源 ip 數(shù)組 (僅當(dāng) trustProxy 開(kāi)啟時(shí)有效)
  • hostname - 請(qǐng)求方的主機(jī)名
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)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)