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.rawinstead) - the incoming HTTP request from Node coreserver- The Fastify server instance, scoped to the current encapsulation contextid- the request idlog- the logger instance of the incoming requestip- the IP address of the incoming requestips- an array of the IP addresses, ordered from closest to furthest, in theX-Forwarded-Forheader of the incoming request (only when thetrustProxyoption is enabled)hostname- the hostname of the incoming request (derived fromX-Forwarded-Hostheader when thetrustProxyoption is enabled)protocol- the protocol of the incoming request (httpsorhttp)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, usesocketinstead. The underlying connection of the incoming request.socket- the underlying connection of the incoming requestcontext- A Fastify internal object. You should not use it directly or modify it. It is usefull to access one special key:context.config- The routeconfigobject.
1. fastify.post('/:params', options, function (request, reply) {
2. console.log(request.body)
3. console.log(request.query)
4. console.log(request.params)
5. console.log(request.headers)
6. console.log(request.raw)
7. console.log(request.server)
8. console.log(request.id)
9. console.log(request.ip)
10. console.log(request.ips)
11. console.log(request.hostname)
12. console.log(request.protocol)
13. request.log.info('some info')
14. })
