Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 15, 2022
1 parent 2987aae commit 1814ddd
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions docs/content/2.guide/2.features/9.server-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu

### Server Storage

Nitro Provides a cross platform [Stroage Layer](https://nitro.unjs.io/guide/storage.html). In oder to configure additional storage mountpoints, you can use `nitro.storage`
Nitro Provides a cross platform [Stroage Layer](https://nitro.unjs.io/guide/storage.html). In oder to configure additional storage mountpoints, you can use `nitro.storage`.

#### Example: Using Redis

Expand All @@ -256,42 +256,37 @@ export default defineNuxtConfig({
Create a new file in `server/api/test.post.ts`:

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

Create a new file in `server/api/test.get.ts`:

```ts [/server/api/test.get.ts]
export default async (req, res) => {
const data = await useStorage().getItem('redis:nuxt3-redis')
export default async defineEventHandler(event => {
const data = await useStorage().getItem('redis:test')
return data
}
})
```

Create a new file in `app.vue`:

```vue [app.vue]
<template>
<div>
<div>Post state: {{resDataSuccess}}</div>
<div>Post state: {{ resDataSuccess }}</div>
<div>Get Data: {{ resData.text }}</div>
</div>
</template>
<script setup lang="ts">
const { data: resDataSuccess } = await useFetch(
'/api/test',
{
const { data: resDataSuccess } = await useFetch('/api/test', {
method: 'post',
body: {
text: 'Welcome To Nuxt3'
}
}
)
body: { text: 'Nuxt is Awesome!' }
})
const { data: resData } = await useFetch('/api/test')
</script>
```

0 comments on commit 1814ddd

Please sign in to comment.