1 Star 0 Fork 1

xmc/fastapi-tutorial

forked from andy/fastapi-tutorial 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hello_world.py 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ = '__Jack__'
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI() # 这里不一定是app,名字随意
class CityInfo(BaseModel):
province: str
country: str
is_affected: Optional[bool] = None # 与bool的区别是可以不传,默认是null
# @app.get('/')
# def hello_world():
# return {'hello': 'world'}
#
#
# @app.get('/city/{city}')
# def result(city: str, query_string: Optional[str] = None):
# return {'city': city, 'query_string': query_string}
#
#
# @app.put('/city/{city}')
# def result(city: str, city_info: CityInfo):
# return {'city': city, 'country': city_info.country, 'is_affected': city_info.is_affected}
#
@app.get('/')
async def hello_world():
return {'hello': 'world'}
@app.get('/city/{city}')
async def result(city: str, query_string: Optional[str] = None):
return {'city': city, 'query_string': query_string}
@app.put('/city/{city}')
async def result(city: str, city_info: CityInfo):
return {'city': city, 'country': city_info.country, 'is_affected': city_info.is_affected}
# 启动命令:uvicorn hello_world:app --reload
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xmc2018/fastapi-tutorial.git
git@gitee.com:xmc2018/fastapi-tutorial.git
xmc2018
fastapi-tutorial
fastapi-tutorial
master

搜索帮助