FastAPI - Dependency Injection
Consider this FastAPI code snippet:
What will be the response after calling GET /add/5 followed by GET /add/3?
from fastapi import FastAPI, Depends
app = FastAPI()
class Accumulator:
def __init__(self):
self.total = 0
def __call__(self, value: int):
self.total += value
return self.total
acc = Accumulator()
@app.get('/add/{value}')
async def add(value: int, total: int = Depends(acc)):
return {'total': total}What will be the response after calling GET /add/5 followed by GET /add/3?
