请求
Fastify
Request
处理函数的第一个参数是 Request.
Request 是 Fastify 的核心对象,包含了以下字段:
query- 解析后的 querystringbody- 消息主体params- URL 参数headers- headersraw- Node 原生的 HTTP 请求req(不推荐,请使用.raw) - Node 原生的 HTTP 请求id- 请求 idlog- 请求的日志实例ip- 请求方的 ip 地址ips- x-forwarder-for header 中保存的请求源 ip 数组,按访问先后排序 (仅当trustProxy开启时有效)hostname- 请求方的主机名 (当trustProxy启用时,从X-Forwarded-Hostheader 中获取)protocol- 请求协议 (https或http)method- 请求方法url- 请求路径routerMethod- 处理请求的路由函数routerPath- 处理请求的路由的匹配模式is404- 当请求被 404 处理时为 true,反之为 falseconnection- 不推荐,请使用socket。请求的底层连接socket- 请求的底层连接
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)
console.log(request.protocol)
request.log.info('some info')
})
