5. API Reference¶
5.1. tozti.utils¶
-
exception
tozti.utils.APIError(msg=None, status=None, **kwargs)¶ Base class for API errors.
-
to_response()¶ Create an aiohttp.web.Response signifiying the error.
-
-
class
tozti.utils.ExtendedJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ JSON encoder handling datetime.datetime and uuid.UUID.
-
class
tozti.utils.RouteDef(path, name=None)¶ Definition of a route.
The method
get(),post(),put(), etc can be used as decorators to specify the handler for the given HTTP method.-
any(handler)¶ Decorator used to specify handler for every method.
-
delete(handler)¶ Decorator used to specify
DELETEmethod handler.
-
get(handler)¶ Decorator used to specify
GETmethod handler.
-
head(handler)¶ Decorator used to specify
HEADmethod handler.
-
options(handler)¶ Decorator used to specify
OPTIONSmethod handler.
-
patch(handler)¶ Decorator used to specify
PATCHmethod handler.
-
post(handler)¶ Decorator used to specify
GETmethod handler.
-
put(handler)¶ Decorator used to specify
PUTmethod handler.
-
register(app)¶ Add all our routes to the given aiohttp.web.Application.
-
route(*meth)¶ Decorator (with arguments) used to specify HTTP handler.
-
-
class
tozti.utils.RouterDef¶ Handle route definitions.
This object can be used as argument to
aiohttp.web.UrlDispatcher.add_routes().Sample usage:
router = RouterDef() route = router.add_route('/foo') @route.get def handle_get(req): return ...
See aiohttp for more informations on resources and routing.
-
add_prefix(prefix)¶ Prefix every contained route.
-
add_route(path, name=None)¶ Add and return a route with given path to the router.
-
-
tozti.utils.json_response(data, **kwargs)¶ Wrapper for aiohttp.web.json_response with extended JSON encoder.
-
tozti.utils.validate(inst, schema)¶ Validate data against a JsonSchema.