mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
docs: update and shorten server example (#22583)
This commit is contained in:
parent
99375d688c
commit
20efac7d57
@ -152,7 +152,10 @@ Server routes can use dynamic parameters within brackets in the file name like `
|
||||
**Example:**
|
||||
|
||||
```ts [server/api/hello/[name\\].ts]
|
||||
export default defineEventHandler((event) => `Hello, ${event.context.params.name}!`)
|
||||
export default defineEventHandler((event) => {
|
||||
const name = getRouterParam(event, 'name')
|
||||
return `Hello, ${name}!`
|
||||
})
|
||||
```
|
||||
|
||||
You can now universally call this API using `await $fetch('/api/hello/nuxt')` and get `Hello, nuxt!`.
|
||||
|
Loading…
Reference in New Issue
Block a user