特に意味はないけどHTTPリクエストを平行に処理し、HTTPステータスコードを足すAPI
from fastapi import FastAPI
import asyncio
import aiohttp
app = FastAPI()
async def get():
async with aiohttp.ClientSession() as session:
async with session.get('http://python.org') as response:
return response.status
@app.get("/")
async def main():
a, b = await asyncio.gather(get(), get())
return a + b
適切にprintすれば、きちんと非同期処理できていることがわかる。