I want to count the number of requests in a specific URL path.
app = FastAPI()
counter = 0
@app.get("/do_something")
async def do_something():
global counter
counter += 1
return {"message": "Hello World"}
Is this code ok? The counter should be thread safe? asincio safe? Is that the right way to count requests (Without DB)? Is there a meaning for the "async" in the "do_something" function in this situation? And how to make it work with several workers?