Created
February 27, 2018 02:43
-
-
Save knowsuchagency/bdcc9ccf1656d216f46bb38a53d7b8e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def authors(request): | |
"""Return json response of authors based on query params.""" | |
connection = request.app['connection'] | |
with log_request(request): | |
# parse values from query params | |
first_name = request.query.get('first_name') | |
last_name = request.query.get('last_name') | |
age = None or int(request.query.get('age', 0)) | |
limit = int(request.query.get('limit', 0)) | |
# client may not want/need book information | |
no_books = str(request.query.get('no_books','')).lower().startswith('t') | |
query_db = partial( | |
fetch_authors, | |
request.app['connection'], | |
first_name=first_name, | |
last_name=last_name, | |
age=age, | |
limit=limit, | |
no_books=no_books | |
) | |
query_db_task = request.loop.run_in_executor(None, query_db) | |
authors: T.List[dict] = await query_db_task | |
response = web.json_response(authors) | |
with log_response(response): | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment