docs: add api req helpers example (#2726)

This commit is contained in:
gregg-cbs 2022-01-17 12:56:12 +02:00 committed by GitHub
parent 0eed770104
commit 1033a223ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -49,6 +49,22 @@ export default async (req: IncomingMessage, res: ServerResponse) => {
}
```
#### Accessing req data
```js
import { useBody, useCookies, useQuery } from 'h3'
export default async (req, res) => {
const query = await useQuery(req)
const body = await useBody(req) // only for POST request
const cookies = useCookies(req)
return { query, body, cookies }
}
```
Learn more about [h3 methods](https://www.jsdocs.io/package/h3#package-index-functions).
## Server Middleware
Nuxt will automatically read in any files in the `~/server/middleware` to create server middleware for your project.