I'm developing a simple application with FastAPI.
I need a function to be called as endpoint for a certain route. Everything works just fine with the function's default parameters, but wheels come off the bus as soon as I try to override one of them.
Example. This works just fine:
async def my_function(request=Request, clientname='my_client'):
print(request.method)
print(clientname)
## DO OTHER STUFF...
return SOMETHING
private_router.add_route('/api/my/test/route', my_function, ['GET'])
This returns an error instead:
async def my_function(request=Request, clientname='my_client'):
print(request.method)
print(clientname)
## DO OTHER STUFF...
return SOMETHING
private_router.add_route('/api/my/test/route', my_function(clientname='my_other_client'), ['GET'])
The Error:
INFO: 127.0.0.1:60005 - "GET /api/my/test/route HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
...
...
TypeError: 'coroutine' object is not callable
The only difference is I'm trying to override the clientname
value in my_function
.
It is apparent that this isn't the right syntax but I looked everywhere and I'm just appalled that the documentation about the add_route
method is nowhere to be found.
Is anyone able to point me to the right way to do this supposedly simple thing?
Thanks!