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
Copy file name to clipboardExpand all lines: docs/en/guide/handler-context.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Handler Context
2
2
3
-
The **Handler Context** manages request processing - accessing request data, building responses, and extending functionality per request. It's passed to every route handler and contains everything you need to process HTTP requests.
3
+
The Handler Context manages request processing - accessing request data, building responses, and extending functionality per request. It's passed to every route handler and contains everything you need to process HTTP requests.
4
4
5
5
## What is Handler Context?
6
6
7
-
The **KoriHandlerContext** is passed to every route handler and gives you access to request data, response builders, and the application environment:
7
+
The KoriHandlerContext is passed to every route handler and gives you access to request data, response builders, and the application environment:
8
8
9
9
```typescript
10
10
typeKoriHandlerContext<Env, Req, Res> = {
@@ -23,14 +23,7 @@ type KoriHandlerContext<Env, Req, Res> = {
23
23
};
24
24
```
25
25
26
-
**Used for:**
27
-
28
-
- Processing HTTP requests
29
-
- Accessing request data
30
-
- Building responses
31
-
- Per-request logic
32
-
33
-
Handler context supports request and response extensions for adding custom functionality.
26
+
Use it for processing HTTP requests, accessing request data, building responses, and per-request logic. Handler context supports request and response extensions for adding custom functionality.
Copy file name to clipboardExpand all lines: docs/en/guide/instance-context.md
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Instance Context
2
2
3
-
The **Instance Context** manages your application's lifecycle - initialization, configuration, and shutdown. It's where you set up shared resources and configure your application environment.
3
+
The Instance Context manages your application's lifecycle - initialization, configuration, and shutdown. It's where you set up shared resources and configure your application environment.
4
4
5
5
## What is Instance Context?
6
6
7
-
The **KoriInstanceContext** handles application-wide concerns that happen once when your app starts up or shuts down:
7
+
The KoriInstanceContext handles application-wide concerns that happen once when your app starts up or shuts down:
When defining content types, you can explicitly control how the request body is parsed using the `parseType` option. This is useful for non-standard content types or when you want to force a specific parsing method.
155
+
156
+
The available parse types are: `'json'`, `'form'`, `'text'`, `'binary'`, and `'auto'` (default).
157
+
158
+
```typescript
159
+
const WebhookSchema =z.object({
160
+
event: z.string(),
161
+
payload: z.record(z.unknown()),
162
+
});
163
+
164
+
app.post('/webhook', {
165
+
requestSchema: zodRequestSchema({
166
+
body: {
167
+
content: {
168
+
// Parse custom content type as JSON
169
+
'application/vnd.custom+json': {
170
+
schema: WebhookSchema,
171
+
parseType: 'json',
172
+
},
173
+
// Parse binary data
174
+
'application/octet-stream': {
175
+
schema: z.instanceof(ArrayBuffer),
176
+
parseType: 'binary',
177
+
},
178
+
},
179
+
},
180
+
}),
181
+
handler: (ctx) => {
182
+
const body =ctx.req.validatedBody();
183
+
// ...
184
+
},
185
+
});
186
+
```
187
+
146
188
## Error Handling
147
189
148
190
Kori provides flexible error handling for validation failures with multiple levels of customization.
The type inference works by parsing the route string at compile time and extracting parameter names, helping prevent typos and improve IDE autocompletion.
94
94
95
-
**Important:** Type inference only works when you pass the route path as a string literal directly to the route method. It does **not** work for:
95
+
Note that type inference only works when you pass the route path as a string literal directly to the route method. It does not work for:
96
96
97
-
- Routes defined with variables: `const path = '/users/:id'; app.get(path, ...)` - no inference
98
-
- Path parameters from parent routes (defined in `createChild` prefix) - these are not included in the inferred type
97
+
- Routes defined with variables: `const path = '/users/:id'; app.get(path, ...)`
98
+
- Path parameters from parent routes (defined in `createChild` prefix)
99
99
100
-
Only parameters defined directly in the string literal of the route method itself will be type-safe.
100
+
These parameters can still be accessed at runtime, but without autocomplete and typed as `string | undefined`.
0 commit comments