diff --git a/docs/content/3.docs/2.directory-structure/12.server.md b/docs/content/3.docs/2.directory-structure/12.server.md index ca520c75140..2226fb5fcbf 100644 --- a/docs/content/3.docs/2.directory-structure/12.server.md +++ b/docs/content/3.docs/2.directory-structure/12.server.md @@ -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. diff --git a/examples/use-async-data/app.vue b/examples/use-async-data/app.vue index 84038f49336..673d4689e75 100644 --- a/examples/use-async-data/app.vue +++ b/examples/use-async-data/app.vue @@ -3,7 +3,7 @@ const { data, refresh, pending } = await useAsyncData('/api/hello', () => $fetch