Using asynchronous path operations
When it comes to improving performance, FastAPI is an asynchronous framework, and it uses Python’s AsyncIO principles and concepts to create a REST API implementation that can run separately and independently from the application’s main thread. The idea also applies to how a background task is executed. Now, to create an asynchronous REST endpoint, attach async
to the func
signature of the service:
@router.get("/feedback/list") async def show_tourist_post(touristId: UUID): tourist_posts = [assess for assess in feedback_tour.values() if assess.tourist_id == touristId] tourist_posts_json = jsonable_encoder(tourist_posts) return JSONResponse(content=tourist_posts_json, status_code...