nonebot2/docs/api/drivers/fastapi.md

119 lines
1.6 KiB
Markdown
Raw Normal View History

2020-10-11 13:17:40 +08:00
---
contentSidebar: true
sidebarDepth: 0
---
# NoneBot.drivers.fastapi 模块
2020-10-16 01:10:46 +08:00
## FastAPI 驱动适配
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
2020-10-11 13:17:40 +08:00
## _class_ `Driver`
2020-12-07 00:52:26 +08:00
基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver)
2020-10-11 13:17:40 +08:00
2020-10-16 01:10:46 +08:00
FastAPI 驱动框架
2020-10-11 13:17:40 +08:00
2020-12-02 15:14:24 +08:00
* **上报地址**
* `/{adapter name}/`: HTTP POST 上报
* `/{adapter name}/http/`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
* `/{adapter name}/ws/`: WebSocket 上报
2020-10-16 01:10:46 +08:00
### _property_ `type`
驱动名称: `fastapi`
### _property_ `server_app`
`FastAPI APP` 对象
### _property_ `asgi`
`FastAPI APP` 对象
### _property_ `logger`
fastapi 使用的 logger
### `on_startup(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `on_shutdown(func)`
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI
2020-11-13 01:46:26 +08:00
### _async_ `_handle_http(adapter, request, data=Body(Ellipsis))`
2020-10-16 01:10:46 +08:00
用于处理 HTTP 类型请求的函数
2020-11-13 01:46:26 +08:00
### _async_ `_handle_ws_reverse(adapter, websocket)`
2020-10-16 01:10:46 +08:00
用于处理 WebSocket 类型请求的函数
## _class_ `WebSocket`
2020-12-07 00:52:26 +08:00
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)
2020-10-16 01:10:46 +08:00
### _property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _async_ `accept()`
接受 WebSocket 连接请求
### _async_ `close(code=1000)`
关闭 WebSocket 连接请求
### _async_ `receive()`
接收一条 WebSocket 信息
### _async_ `send(data)`
发送一条 WebSocket 信息