特点
- 高性能:基于 Starlette 和 Pydantic,FastAPI 在性能上接近 Node.js 和 Go。
- 自动生成文档:内置 Swagger UI 和 ReDoc,可以自动生成交互式API文档。
- 类型安全:使用 Python 的类型提示,提供数据验证和序列化。
- 异步支持:原生支持异步编程,适合处理高并发请求。
最小化代码结构
| |

服务启动方式
fastapi 开发模式
fastapi dev main.py --host 0.0.0.0 --port 18888

fastapi生产环境模式
fastapi run main.py --host 0.0.0.0 --port 18888

uvicorn生产环境模式
uvicorn main:app --host 0.0.0.0 --port 18888

代码中引入 uvicorn 模块
| |

直接运行脚本文件以启动 uvicorn
自动生成文档
自动生成 SwaggerUI 文档
运行fastapi run main.py --host 127.0.0.1 --port 18888启动服务




命令行下发送请求

