You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 77129d0
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
-130Lines changed: 0 additions & 130 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,45 +154,7 @@ const app = createApp()
154
154
155
155
Internally, Zeta uses [`rou3`](https://www.npmjs.com/package/rou3) to match routes. To add a path parameter, you can use `:name`, `**`, or `**:name`. For type safety, you can use a validation framework to define an object schema for the path parameters.
156
156
157
-
```ts
158
-
import { z } from"zod";
159
157
160
-
const app =createApp()
161
-
.get(
162
-
"/path/:name",
163
-
{
164
-
// Optional: Add type-safety and validation to the route
165
-
path: z.object({
166
-
name: z.coerce.number(),
167
-
}),
168
-
},
169
-
({ path }) => {
170
-
console.log(path.name);
171
-
},
172
-
)
173
-
.get(
174
-
"/path/**",
175
-
{
176
-
path: z.object({
177
-
"**": z.string(),
178
-
}),
179
-
},
180
-
async ({ path }) => {
181
-
console.log(path["**"]);
182
-
},
183
-
)
184
-
.get(
185
-
"/path/**:name",
186
-
{
187
-
path: z.object({
188
-
name: z.string(),
189
-
}),
190
-
},
191
-
({ path }) => {
192
-
console.log(path.name);
193
-
},
194
-
);
195
-
```
196
158
197
159
> Note that path parameters are strings. If your validation framework supports converting strings to other types, like with Zod's [`z.coerce`](https://zod.dev/api?id=coercion) or [`z.stringbool`](https://zod.dev/api?id=stringbool), you can use it to convert the string values to the desired type.
198
160
@@ -342,98 +304,6 @@ app.get(
342
304
343
305
## Life Cycle Hooks
344
306
345
-
You can use any of the following APIs to hook into the request lifecycle:
346
-
347
-
```mermaid
348
-
---
349
-
title: RequestLifeCycle
350
-
---
351
-
graphLR
352
-
A((Client)) -.->B
353
-
B[onGlobalRequest] --"Route Matched"-->D
354
-
B--"Not Found"-->C
355
-
C[onGlobalError] --->J
356
-
D[onTransform] --"Validate Inputs"-->E
357
-
D--"Error thrown"-->C
358
-
E[onBeforeHandle] --->F
359
-
E--"Error thrown"-->C
360
-
F((Handler)) -->G
361
-
F--"Error thrown"-->C
362
-
G[onAfterHandle] --"Validate Response"-->H
363
-
G--"Error thrown"-->C
364
-
H[onMapResponse] --->J
365
-
H--"Error thrown"-->C
366
-
J@{ shape: sm-circ } -.->K
367
-
J--->L
368
-
K((Client))
369
-
L["onGlobalAfterResponse (deferred)"]
370
-
```
371
-
372
-
-`onGlobalRequest`: Called as soon as a request is made to the app.
373
-
- Return value is shallow merged into the `ctx` object for future callbacks.
374
-
-`onTransform`: Called before input parameters have been validated, can be used to transform input values before validation occurs.
375
-
- Return value is shallow merged into the `ctx` object for future callbacks.
376
-
-`onBeforeHandle`: Called after inputs have been validated, right before the route handler is executed.
377
-
- Return value is shallow merged into the `ctx` object for future callbacks.
378
-
-`onAfterHandle`: Called after the route handler is executed.
379
-
- Return value replaces the value returned from the handler.
380
-
-`onMapResponse`: Convert the return value into a [`Response` object](https://developer.mozilla.org/en-US/docs/Web/API/Response).
381
-
- If a `Response` value is returned, send it to the client.
382
-
- If a `Response` value is not returned, Zeta infers the response content type based on the handler's response value.
383
-
-`onGlobalAfterResponse`: Called after the response is sent to the client.
384
-
- Return value is ignored.
385
-
-`onGlobalError`: If an error is thrown at any point in the lifecycle, this hook will be called giving you the opportunity to report the error.
386
-
387
-
There are two types of hooks: global and isolated.
388
-
389
-
-**Global**: These hooks are registered on the final, top-level app, regardless of where they are defined in your app's composition tree. They always run for every request that hits the server. Use these for cross-cutting concerns like logging or authentication.
390
-
-**Isolated**: These hooks only apply to routes defined on the _same app instance_, _after_ the hook is declared. They are perfect for setting up context or running middleware specific to a group of routes (e.g., a plugin).
391
-
392
-
Here's an example combining several different hooks:
0 commit comments