How to make routes folder for all app routes in FastAPI and APIRouter

PHOTO EMBED

Mon Sep 16 2024 09:46:57 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #programming #api #api

# main.py

from fastapi import FastAPI
from routes.tasks import tasks_route

app = FastAPI()

app.include_router(tasks_route)

-------------------------

# routes > tasks.py

from fastapi import APIRouter

tasks_route = APIRouter()

@tasks_route.get('/tasks')
def get_tasks():
  return {'tasks': []}
content_copyCOPY