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
<!--
Before submitting:
- Read CONTRIBUTING.md for workflow
- Read AGENTS.md for architecture (especially if AI-generated)
Air's design principles: semantic APIs with clear docstrings,
concise docs mindful of context window sizes, max readability,
less code is better, zero config is ideal. — airwebframework.org
-->
## What
This is a collection of doc improvements and edits from the point of
view of a new user.
## Pattern
N/A
## Reviewer Focus
- Consistency was applied to the examples
- Updated the examples
- Fixed some broken examples
- Added an alternate way to pass reserved words.
## Checklist
- [X] Diff contains only changes for this task — no unrelated
refactoring or cleanup
- [ ] Addresses exactly one issue or feature
- [ ] New or changed behavior has test coverage
- [ ] This is the simplest viable approach
- [ ] AI provenance section removed or accurate
Copy file name to clipboardExpand all lines: docs/api/routing.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,23 @@
1
-
Routing
1
+
## Routing
2
2
3
-
If you need to knit several Python modules with their own Air views into one, that's where Routing is used. They allow the near seamless combination of multiple Air apps into one. Larger sites are often built from multiple routers.
3
+
If you need to knit several Python modules with their own Air views into one, you will need to use Routing. This allow the near seamless combination of multiple Air apps into one. Larger sites are often built from multiple routers.
4
4
5
-
Let's imagine we have an e-commerce store with a shopping cart app. Use instantiate a `router` object using `air.AirRouter()` just as we would with `air.App()`:
5
+
For this example, let's imagine we have an e-commerce store with a shopping cart app with a `cart.py` and `main.py` file.
6
6
7
-
```python
8
-
# cart.py
7
+
```python title="cart.py"
9
8
import air
10
9
11
10
router = air.AirRouter()
12
11
13
12
14
13
@router.page
15
-
defcart():
14
+
defcart_page():
16
15
return air.H1("I am a shopping cart")
17
16
```
18
17
19
-
Then in our main page we can load that and tie it into our main`app`.
18
+
Then in our main page we can load that and tie it into our `main.py`app.
20
19
21
-
```python
20
+
```python title="main.py"
22
21
import air
23
22
from cart import router as cart_router
24
23
@@ -31,21 +30,24 @@ def index():
31
30
return air.H1("Home page")
32
31
```
33
32
34
-
Note that the router allows sharing of sessions and other application states.
33
+
`AirRouter` allows the sharing of sessions and other application states between routes.
35
34
36
-
In addition, we can add links through the `.url()` method available on route functions, which generates URLs programmatically:
35
+
In addition, we can add links through the `.url()` method available on route functions:
This example uses [Air Tags](api/tags/index.md), which are Python classes that render as HTML. Air Tags are typed and documented, designed to work well with any code completion tool.
148
152
153
+
### Running Air
154
+
155
+
To run the development server, run the following command in your terminal:
156
+
157
+
```sh
158
+
air run
159
+
```
160
+
161
+
Open <http://127.0.0.1:8000> to see the above example running.
162
+
149
163
## Combining FastAPI and Air
150
164
151
165
Air is just a layer over FastAPI. So it is trivial to combine sophisticated HTML pages and a REST API into one app.
`AirForm[ContactMessage]` gives you type-safe validated data. `ContactMessage.create()` writes it to PostgreSQL. Your editor knows the types at every step.
0 commit comments