mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
docs: change deprecated useBody
with readBody
(#8266)
This commit is contained in:
parent
96a8807abf
commit
b1c842e8be
@ -141,7 +141,7 @@ export default defineEventHandler(() => `Default api handler`)
|
|||||||
|
|
||||||
```ts [server/api/submit.post.ts]
|
```ts [server/api/submit.post.ts]
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const body = await useBody(event)
|
const body = await readBody(event)
|
||||||
return { body }
|
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 } })`.
|
You can now universally call this API using `$fetch('/api/submit', { method: 'post', body: { test: 123 } })`.
|
||||||
|
|
||||||
::alert{type=warning title=Attention}
|
::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
|
### 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]
|
```ts [server/api/test.post.ts]
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const body = await useBody(event)
|
const body = await readBody(event)
|
||||||
await useStorage().setItem('redis:test', body)
|
await useStorage().setItem('redis:test', body)
|
||||||
return 'Data is set'
|
return 'Data is set'
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user