A FastAPI utility to allow Controller Class usage
Project description
What this repository contains
A FastAPI utility to allow Controller Class usage
Installation:
install the package
pip install fastapi-router-controller
How to use
In a Class module
from fastapi import APIRouter, Depends
from fastapi_router_controller import Controller
router = APIRouter()
controller = Controller(router)
async def amazing_fn():
return 'amazing_variable'
@controller.resource()
class ExampleController():
# you can define in the Controller init some FastApi Dependency and them are automatically loaded in controller methods
def __init__(self, x: Foo = Depends(amazing_fn)):
self.x = x
@controller.route.get(
'/some_aoi',
summary='A sample description')
def sample_api(self):
print(self.x) # -> amazing_variable
return 'A sample response'
Load the controller to the main FastAPI app
from fastapi import FastAPI
from fastapi_router_controller import Controller
import ExampleController
app = FastAPI(
title='A sample application using fastapi_router_controller',
version="0.1.0")
example_controller = ExampleController()
app.include_router(example_controller.router())
For some Example use-cases visit the example folder
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for fastapi-router-controller-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8fc0ac9eaa32aaf7a11d9d03d0f8154894e4766b01ba137c5aad37cb05f4b2d |
|
MD5 | 15284e94cdbceefd5fe76863a104f404 |
|
BLAKE2b-256 | 11a59bd0f1160a51b1a7ecea029e11a036923e7816e579be078aeb3cbd874f92 |