Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/content/2.guide/2.directory-structure/1.server.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ export default defineEventHandler(() => `Default api handler`)

```ts [server/api/submit.post.ts]
export default defineEventHandler(async (event) => {
const body = await useBody(event)
const body = await readBody(event)
return { body }
})
```

You can now universally call this API using `$fetch('/api/submit', { method: 'post', body: { test: 123 } })`.

::alert{type=warning title=Attention}
We are using `submit.post.ts` in the filename only to match requests with `POST` method that can accept the request body. When using `useBody` within a GET request, `useBody` will throw a `405 Method Not Allowed` HTTP error.
We are using `submit.post.ts` in the filename only to match requests with `POST` method that can accept the request body. When using `readBody` within a GET request, `readBody` will throw a `405 Method Not Allowed` HTTP error.
::

### Handling Requests With Query Parameters
Expand Down Expand Up @@ -275,7 +275,7 @@ Create a new file in `server/api/test.post.ts`:

```ts [server/api/test.post.ts]
export default defineEventHandler(async (event) => {
const body = await useBody(event)
const body = await readBody(event)
await useStorage().setItem('redis:test', body)
return 'Data is set'
})
Expand Down