Skip to content

Commit

Permalink
docs: use defineEventHandler instead of eventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes committed Jul 16, 2023
1 parent e87e2ba commit 180c37f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions docs/content/1.guide/3.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you are using [Nuxt](https://nuxt.com), move the `api/` and `routes/` inside

```ts
// api/hello.ts
export default eventHandler(() => {
export default defineEventHandler(() => {
return { hello: 'world' }
})
```
Expand All @@ -45,7 +45,7 @@ You can now universally call this API using `await $fetch('/api/hello')`.

```js
// routes/hello/[name].ts
export default eventHandler(event => `Hello ${event.context.params.name}!`)
export default defineEventHandler(event => `Hello ${event.context.params.name}!`)
```

::code-group
Expand All @@ -58,7 +58,7 @@ To include the `/`, use `[...name].ts`:

```js
// routes/hello/[...name].ts
export default eventHandler(event => `Hello ${event.context.params.name}!`)
export default defineEventHandler(event => `Hello ${event.context.params.name}!`)
```

::code-group
Expand All @@ -74,7 +74,7 @@ API route with a specific HTTP request method (get, post, put, delete, options a
::code-group
```js [GET]
// routes/users/[id].get.ts
export default eventHandler(async (event) => {
export default defineEventHandler(async (event) => {
const { id } = event.context.params
// TODO: fetch user by id
return `User profile!`
Expand All @@ -83,7 +83,7 @@ export default eventHandler(async (event) => {

```js [POST]
// routes/users.post.ts
export default eventHandler(async event => {
export default defineEventHandler(async event => {
const body = await readBody(event)
// TODO: Handle body and add user
return { updated: true }
Expand All @@ -97,7 +97,7 @@ Check out [h3 JSDocs](https://www.jsdocs.io/package/h3#package-index-functions)

```js
// routes/[...].ts
export default eventHandler(event => `Default page`)
export default defineEventHandler(event => `Default page`)
```

## Route Rules
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.guide/5.cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const cachedGHStars = cachedFunction(async (repo: string) => {
})
```
```ts [api/stars/[...repo].ts]
export default eventHandler(async (event) => {
export default defineEventHandler(async (event) => {
const repo = event.context.params.repo
const stars = await cachedGHStars(repo).catch(() => 0)

Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.deploy/providers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ You need to either set `KV_REST_API_URL` and `KV_REST_API_TOKEN` environment var
You can now access data store in any event handler:

```ts
export default eventHandler(async (event) => {
export default defineEventHandler(async (event) => {
const dataStorage = useStorage("data");
await dataStorage.setItem("hello", "world");
return {
Expand Down
6 changes: 3 additions & 3 deletions docs/content/3.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ For example:

```ts
import { defineNitroConfig } from 'nitropack/config'
import { eventHandler } from 'h3'
import { defineEventHandler } from 'h3'

export default defineNitroConfig({
devHandlers: [
{
route: '/',
handler: eventHandler((event) => {
handler: defineEventHandler((event) => {
console.log(event)
})
}
Expand All @@ -268,7 +268,7 @@ export default defineNitroConfig({
```

::alert{type=info}
Note that `eventHandler` is a helper function from [`h3`](https://github.com/unjs/h3) library.
Note that `defineEventHandler` is a helper function from [`h3`](https://github.com/unjs/h3) library.
::

### `devProxy`
Expand Down

0 comments on commit 180c37f

Please sign in to comment.