docs: change deprecated useBody with readBody (#8266)

This commit is contained in:
Daniel Kelly 2022-10-18 03:46:47 -05:00 committed by GitHub
parent 96a8807abf
commit b1c842e8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,7 +141,7 @@ 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 }
})
```
@ -149,7 +149,7 @@ export default defineEventHandler(async (event) => {
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
@ -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'
})