Request
The first parameter of the handler function is Request
.
Request is a core Fastify object containing the following fields:
query
- the parsed querystringbody
- the bodyparams
- the params matching the URLheaders
- the headersraw
- the incoming HTTP request from Node corereq
(deprecated, use.raw
instead) - the incoming HTTP request from Node coreid
- the request idlog
- the logger instance of the incoming requestip
- the IP address of the incoming requestips
- an array of the IP addresses in theX-Forwarded-For
header of the incoming request (only when thetrustProxy
option is enabled)hostname
- the hostname of the incoming request (derived fromX-Forwarded-Host
header when thetrustProxy
option is enabled)protocol
- the protocol of the incoming request (https
orhttp
)method
- the method of the incoming requesturl
- the url of the incoming requestrouterMethod
- the method defined for the router that is handling the requestrouterPath
- the path pattern defined for the router that is handling the requestis404
- true if request is being handled by 404 handler, false if it is notconnection
- Deprecated, usesocket
instead. The underlying connection of the incoming request.socket
- the underlying connection of the incoming request
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')
})