mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
docs: add api req helpers example (#2726)
This commit is contained in:
parent
0eed770104
commit
1033a223ff
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user