Simple decorator for dealing with typed query parameters.
supercell.queryparam.
QueryParams
(params, kwargs_name='query')¶Simple middleware for ensuring types in query parameters.
A simple example:
@QueryParams((
('limit', IntType()),
('q', StringType())
)
)
@s.async
def get(self, *args, **kwargs):
limit = kwargs.get('limit', 0)
q = kwargs.get('q', None)
...
If a param is required, simply set the required property for the schematics type definition:
@QueryParams((
('limit', IntType(required=True)),
('q', StringType())
)
)
...
If the parameter is missing, a HTTP 400 error is raised.
By default the dictionary containing the typed query parameters is added to the kwargs of the method with the key query. In order to change that, simply change the key in the definition:
@QueryParams((
...
),
kwargs_name='myquery'
)
...