Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency
Created February 27, 2018 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knowsuchagency/bdcc9ccf1656d216f46bb38a53d7b8e9 to your computer and use it in GitHub Desktop.
Save knowsuchagency/bdcc9ccf1656d216f46bb38a53d7b8e9 to your computer and use it in GitHub Desktop.
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