5. API Reference¶
5.1. tozti.utils
¶
-
exception
tozti.utils.
APIError
(template=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
DELETE
method handler.
-
get
(handler)¶ Decorator used to specify
GET
method handler.
-
head
(handler)¶ Decorator used to specify
HEAD
method handler.
-
options
(handler)¶ Decorator used to specify
OPTIONS
method handler.
-
patch
(handler)¶ Decorator used to specify
PATCH
method handler.
-
post
(handler)¶ Decorator used to specify
GET
method handler.
-
put
(handler)¶ Decorator used to specify
PUT
method 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.