UNPKG

1.15 kBMarkdownView Raw
1<h1 align="center">Fastify</h1>
2
3## Request
4The first parameter of the handler function is `Request`.<br>
5Request is a core Fastify object containing the following fields:
6- `query` - the parsed querystring
7- `body` - the body
8- `params` - the params matching the URL
9- `headers` - the headers
10- `raw` - the incoming HTTP request from Node core *(you can use the alias `req`)*
11- `id` - the request id
12- `log` - the logger instance of the incoming request
13- `ip` - the IP address of the incoming request
14- `ips` - an array of the IP addresses in the `X-Forwarded-For` header of the incoming request (only when the [`trustProxy`](https://github.com/fastify/fastify/blob/master/docs/Server.md#factory-trust-proxy) option is enabled)
15- `hostname` - the hostname of the incoming request
16
17```js
18fastify.post('/:params', options, function (request, reply) {
19 console.log(request.body)
20 console.log(request.query)
21 console.log(request.params)
22 console.log(request.headers)
23 console.log(request.raw)
24 console.log(request.id)
25 console.log(request.ip)
26 console.log(request.ips)
27 console.log(request.hostname)
28 request.log.info('some info')
29})
30```