Query Parameter

Simple decorator for dealing with typed query parameters.

class 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'
)
...
Read the Docs v: latest
Versions
latest
v0.4.0
v0.3.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.