From 8822cdd0e8a427840744fa26675a0ba33f9523fa Mon Sep 17 00:00:00 2001
From: Braden Wong <13159333+braden-w@users.noreply.github.com>
Date: Fri, 5 Dec 2025 15:44:40 -0800
Subject: [PATCH 1/4] docs(tutorial): show string status names in lifecycle
examples
Add inline comments showing string alternatives:
- status(418) // or status("I'm a teapot")
- status(401) // or status("Unauthorized")
Also add explanatory note that status() accepts both formats.
---
docs/tutorial/getting-started/life-cycle/index.md | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/docs/tutorial/getting-started/life-cycle/index.md b/docs/tutorial/getting-started/life-cycle/index.md
index c11381dd..981dfe32 100644
--- a/docs/tutorial/getting-started/life-cycle/index.md
+++ b/docs/tutorial/getting-started/life-cycle/index.md
@@ -56,12 +56,14 @@ new Elysia()
console.log('This is executed before handler')
if(Math.random() <= 0.5)
- return status(418)
+ return status(418) // or status("I'm a teapot")
}
})
.get('/2', () => 'Hello Elysia!')
```
+The `status` function accepts both numeric codes (`418`) and string status names (`"I'm a teapot"`).
+
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
This is useful for things like authentication, where you want to return a `401 Unauthorized` response if the user is not authenticated.
@@ -99,7 +101,7 @@ new Elysia()
console.log('Run before handler')
if(Math.random() <= 0.5)
- return status(418)
+ return status(418) // or status("I'm a teapot")
}
})
.get('/2', () => 'Hello Elysia!')
@@ -120,7 +122,7 @@ new Elysia()
console.log('This is executed before handler')
if(Math.random() <= 0.5)
- return status(418)
+ return status(418) // or status("I'm a teapot")
})
// "beforeHandle" is applied
.get('/auth', () => {
@@ -147,7 +149,7 @@ import { Elysia } from 'elysia'
new Elysia()
.onBeforeHandle(({ query: { name }, status }) => {
- if(!name) return status(401)
+ if(!name) return status(401) // or status("Unauthorized")
})
.get('/auth', ({ query: { name = 'anon' } }) => {
return `Hello ${name}!`
From a41ff8ef30127f3ed85c6674a065037b3a747f28 Mon Sep 17 00:00:00 2001
From: Braden Wong <13159333+braden-w@users.noreply.github.com>
Date: Fri, 5 Dec 2025 16:24:28 -0800
Subject: [PATCH 2/4] docs(tutorial): clarify status accepts both number and
string names
- Remove '// or' comments in favor of clearer explanatory text
- Add note explaining 418 = 'I'm a teapot' with link to status tutorial
- Use status("Unauthorized") for auth example (clearer than 401)
- Keep status(418) for teapot examples
---
docs/tutorial/getting-started/life-cycle/index.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/tutorial/getting-started/life-cycle/index.md b/docs/tutorial/getting-started/life-cycle/index.md
index 981dfe32..d86654ed 100644
--- a/docs/tutorial/getting-started/life-cycle/index.md
+++ b/docs/tutorial/getting-started/life-cycle/index.md
@@ -56,13 +56,13 @@ new Elysia()
console.log('This is executed before handler')
if(Math.random() <= 0.5)
- return status(418) // or status("I'm a teapot")
+ return status(418)
}
})
.get('/2', () => 'Hello Elysia!')
```
-The `status` function accepts both numeric codes (`418`) and string status names (`"I'm a teapot"`).
+Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status("I'm a teapot")`. See Status and Headers for more on using status codes.
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
@@ -101,7 +101,7 @@ new Elysia()
console.log('Run before handler')
if(Math.random() <= 0.5)
- return status(418) // or status("I'm a teapot")
+ return status(418)
}
})
.get('/2', () => 'Hello Elysia!')
@@ -122,7 +122,7 @@ new Elysia()
console.log('This is executed before handler')
if(Math.random() <= 0.5)
- return status(418) // or status("I'm a teapot")
+ return status(418)
})
// "beforeHandle" is applied
.get('/auth', () => {
@@ -149,7 +149,7 @@ import { Elysia } from 'elysia'
new Elysia()
.onBeforeHandle(({ query: { name }, status }) => {
- if(!name) return status(401) // or status("Unauthorized")
+ if(!name) return status("Unauthorized")
})
.get('/auth', ({ query: { name = 'anon' } }) => {
return `Hello ${name}!`
From 041d9d110803f85088e939cb8875971cde88f94f Mon Sep 17 00:00:00 2001
From: Braden Wong
Date: Fri, 5 Dec 2025 17:29:51 -0800
Subject: [PATCH 3/4] style: use single quotes for status strings
---
docs/tutorial/getting-started/life-cycle/index.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/tutorial/getting-started/life-cycle/index.md b/docs/tutorial/getting-started/life-cycle/index.md
index d86654ed..1448243f 100644
--- a/docs/tutorial/getting-started/life-cycle/index.md
+++ b/docs/tutorial/getting-started/life-cycle/index.md
@@ -62,7 +62,7 @@ new Elysia()
.get('/2', () => 'Hello Elysia!')
```
-Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status("I'm a teapot")`. See Status and Headers for more on using status codes.
+Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status('I\'m a teapot')`. See Status and Headers for more on using status codes.
When `beforeHandle` returns a value, it will skip the handler and return the value instead.
@@ -149,7 +149,7 @@ import { Elysia } from 'elysia'
new Elysia()
.onBeforeHandle(({ query: { name }, status }) => {
- if(!name) return status("Unauthorized")
+ if(!name) return status('Unauthorized')
})
.get('/auth', ({ query: { name = 'anon' } }) => {
return `Hello ${name}!`
From 0edd01682a872a4180266e53c2bef5d611f837b5 Mon Sep 17 00:00:00 2001
From: Braden Wong
Date: Fri, 5 Dec 2025 17:39:03 -0800
Subject: [PATCH 4/4] style: use double quotes for strings with apostrophes
---
docs/tutorial/getting-started/life-cycle/index.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/tutorial/getting-started/life-cycle/index.md b/docs/tutorial/getting-started/life-cycle/index.md
index 1448243f..a2064fed 100644
--- a/docs/tutorial/getting-started/life-cycle/index.md
+++ b/docs/tutorial/getting-started/life-cycle/index.md
@@ -62,7 +62,7 @@ new Elysia()
.get('/2', () => 'Hello Elysia!')
```
-Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status('I\'m a teapot')`. See Status and Headers for more on using status codes.
+Here we use `status(418)` which is the "I'm a teapot" status code. You can also use the string name directly: `status("I'm a teapot")`. See Status and Headers for more on using status codes.
When `beforeHandle` returns a value, it will skip the handler and return the value instead.