kyoukai.routegroup

Route groups are classes that allow you to group a set of routes together.

Functions

after_request(func) Helper decorator to mark a function as a post-request hook.
before_request(func) Helper decorator to mark a function as a pre-request hook.
errorhandler(code) A companion function to the RouteGroup class.
get_rg_bp(group) Gets the Blueprint created from a RouteGroup.
hook(type_) Marks a function as a hook.
route(url[, methods]) A companion function to the RouteGroup class.

Classes

RouteGroup A route group is a class that contains multiple methods that are decorated with the route decorator.
RouteGroupType(name, bases, class_body, **kwargs) The metaclass for a route group.
kyoukai.routegroup.get_rg_bp(group)[source]

Gets the Blueprint created from a RouteGroup.

class kyoukai.routegroup.RouteGroupType(name, bases, class_body, **kwargs)[source]

Bases: type

The metaclass for a route group.

This is responsible for passing the keyword arguments to the metaclass.

Override of __init__ to store the blueprint params.

_init_blueprint(obb)[source]

Initializes the Blueprint used by this route group.

Parameters:obb – The route group instance to intialize.
mro() → list

return a type’s method resolution order

kyoukai.routegroup.route(url, methods=('GET', ), **kwargs)[source]

A companion function to the RouteGroup class. This follows Blueprint.route() in terms of arguments, and marks a function as a route inside the class.

This will return the original function, with some attributes attached:

  • in_group: Marks the function as in the route group.
  • rg_delegate: Internal. The type of function inside the group this is.
  • route_kwargs: Keyword arguments to provide to wrap_route.
  • route_url: The routing URL to provide to add_route.
  • route_methods: The methods for the route.
  • route_hooks: A defaultdict of route-specific hooks.

Additionally, the following methods are added.

  • hook: A decorator that adds a hook of type type_.
  • before_request: A decorator that adds a pre hook.
  • after_request: A decorator that adds a post hook.

New in version 2.1.1.

Changed in version 2.1.3: Added the ability to add route-specific hooks.

Parameters:
  • url (str) – The routing URL of the route.
  • methods (Iterable[str]) – An iterable of methods for the route.
kyoukai.routegroup.errorhandler(code)[source]

A companion function to the RouteGroup class. This follows Blueprint.errorhandler() in terms of arguments.

Parameters:code (int) – The code for the error handler.
kyoukai.routegroup.hook(type_)[source]

Marks a function as a hook.

Parameters:type (str) – The type of hook to mark.
kyoukai.routegroup.before_request(func)[source]

Helper decorator to mark a function as a pre-request hook.

kyoukai.routegroup.after_request(func)[source]

Helper decorator to mark a function as a post-request hook.

class kyoukai.routegroup.RouteGroup[source]

Bases: object

A route group is a class that contains multiple methods that are decorated with the route decorator. They produce a blueprint that can be added to the tree that includes all methods in the route group.

class MyGroup(RouteGroup, url_prefix="/api/v1"):
    def __init__(self, something: str):
        self.something = something
        
    @route("/ping")
    async def ping(self, ctx: HTTPRequestContext):
        return '{"response": self.something}'

Blueprint parameters can be passed in the class call.

To add the route group as a blueprint, use Blueprint.add_route_group(MyGroup, *args, **kwargs)().