fastAPI-aiohttp-example icon indicating copy to clipboard operation
fastAPI-aiohttp-example copied to clipboard

How to use and test fastAPI with an aiohttp client

Python

Full exemple of FastAPI with an aiohttp client

This is an exemple with FastAPI but you can use this logic with any async ( ASGI ) web framework

Implemented logic :

(with a fake server mocking answer of aiohttp)

  • Open ClientSession at fastAPI startup

  • Close ClientSession at fastAPI shutdown

Tests

  • fastAPI endpoint test
  • aiohttp test