Routes¶
Example¶
Adding routes follows the standard transmute pattern, with a decorator converting a function to an aiohttp route:
import aiohttp_transmute
# define a GET endpoint, taking a query parameter integers left and right,
# which must be integers.
@aiohttp_transmute.describe(paths="/{name}")
async def multiply(request, name: str, left: int, right: int) -> int:
return left + right
# append to your route later
aiohttp_transmute.route(app, multiply)
the aiohttp request argument is supported: it will be passed into any function that has ‘request’ in it’s function signature.
see transmute-core:function for more information on customizing transmute routes.
API Documentation¶
-
aiohttp_transmute.
describe
(**kwargs)¶ describe is a decorator to customize the rest API that transmute generates, such as choosing certain arguments to be query parameters or body parameters, or a different method.
Parameters: - paths (list(str)) – the path(s) for the handler to represent (using swagger’s syntax for a path)
- methods (list(str)) – the methods this function should respond to. if non is set, transmute defaults to a GET.
- query_parameters (list(str)) – the names of arguments that should be query parameters. By default, all arguments are query_or path parameters for a GET request.
- body_parameters (list(str)) – the names of arguments that should be body parameters. By default, all arguments are either body or path parameters for a non-GET request.
- header_parameters (list(str)) – the arguments that should be passed into the header.
- path_parameters (list(str)) – the arguments that are specified by the path. By default, arguments that are found in the path are used first before the query_parameters and body_parameters.