0
0

More than 1 year has passed since last update.

FastAPIでaiohttp

Posted at

特に意味はないけど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すれば、きちんと非同期処理できていることがわかる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0