示例工程 35-asgi-fastapi

35-asgi-fastapi/01-handwritten-asgi/README.md

markdown · 0.6 KB

# 01 · handwritten-asgi
 
**演示**:不装框架,手写 `async def app(scope, receive, send)`;先发 `http.response.start`,再发 `http.response.body`。测试直接收集消息,不需要端口。
**运行**:
 
```sh
uv run python examples/35-asgi-fastapi/01-handwritten-asgi/handwritten_asgi.py
```
 
**预期输出**(3.12.9):
 
```text
status: 200
body: hello asgi
missing: 404 not found
```
 
**依赖**:仅标准库。
**注意**:ASGI 是消息协议,`send` 顺序与字段是契约;`scope` 至少含 `type`/`path`/`headers`,真实服务器还会传 `method`/`query_string` 等。