代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time :2021/7/7 16:21
# @Author :cjw
from typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
# 启动命令 uvicorn hello_world:app --reload
class CityInfo(BaseModel):
province: str # 省
country: str # 市
is_affected: Optional[bool] = None # 是否有感染
# @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_put(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_put(city: str, city_info: CityInfo):
return {'city': city, 'country': city_info.country, 'is_affected': city_info.is_affected}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。