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/dependencies.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,11 @@
2
2
3
3
[← Documentation index](index.md)
4
4
5
-
OxyRoute supports a **linear** list of **named** dependency factories. At request time, each factory is called in order; its return value is injected into the route handler as a **keyword argument** with the given name.
5
+
OxyRoute supports a **linear** list of **named** dependency factories. At request time, each factory is called in order; its return value is injected into the route handler as a **keyword argument** with the given name. Factories that appear **later** in the list are called with **keyword arguments** for every **earlier** name and value (so a factory can depend on a previous one by using the same parameter name, e.g. `def b(a: int): …` when the first tuple is `("a", make_a)`).
6
+
7
+
### Request context (optional)
8
+
9
+
If a factory’s signature includes a parameter named `request`, the extension passes a **dict** (once per request, shared) with string keys: `method`, `path`, `query_string`, and `headers` (a flat `str` → `str` map, when the underlying RSGI scope exposes headers—see the ASGI bridge in `oxyroute.asgi`). Factories that do **not** declare `request` are still called with **no** extra arguments when they have no prior dependencies, preserving older behavior.
6
10
7
11
## Declaring on a route
8
12
@@ -17,7 +21,9 @@ def list_items(db: str) -> str:
17
21
returnf"ok {db}"
18
22
```
19
23
20
-
`factory` can be **sync** or **async** (the extension detects `async` factories and awaits them in order).
24
+
`factory` can be **sync** or **async** (the extension detects `async` factories and awaits them in order). Dependency **names** must be **unique** in the list.
25
+
26
+
**Example (chaining):**`dependencies=[("a", make_a), ("b", make_b)]` with `def make_b(a): return a + 1` — the second callable receives the value bound to `a`.
Copy file name to clipboardExpand all lines: docs/handlers.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ handler(**kwargs)
19
19
|`json`|`read_json_body` is true and body parses as JSON |`dict`/list/values as converted from `serde_json` to Python |
20
20
|`body`| Raw body bytes, when JSON is not used or empty |`bytes`|
21
21
|`claims`|`require_jwt` is true and the JWT validates | The decoded JSON claims as a Python object (typically a `dict`) |
22
-
| Named dependencies |`dependencies=[("name", factory), ...]`| Return value of each factory, in order (see [dependencies.md](dependencies.md)) |
22
+
| Named dependencies |`dependencies=[("name", factory), ...]`| Return value of each factory, in order (see [dependencies.md](dependencies.md)). Only dependencies whose **names** appear on the route handler’s signature (or `**kwargs`) are passed to the handler—intermediate-only dependencies are not forwarded|
23
23
24
24
**JWT:** if `require_jwt` is set but validation fails, the **handler is not called**; the response is 401 (or a dedicated “Expired” string for expired signature when applicable). See [jwt.md](jwt.md).
0 commit comments