apifrom.core.router

Router module for APIFromAnything.

This module defines the Router class that manages the registration and lookup of API endpoints.

Overview

Classes

Functions

Classes

class apifrom.core.router.Router[source]

Router for managing API endpoints.

This class is responsible for registering and looking up API endpoints. It maintains a registry of routes and their associated handlers.

apifrom.core.router.routes

List of registered routes.

Type:

list

Initialize a new Router instance.

apifrom.core.router.add_route(handler, path=None, method='GET', name=None, **kwargs)

Add a route to the router.

param handler:

The function to handle the route.

param path:

The URL path for the route. If None, derived from handler name.

param method:

The HTTP method for the route.

param name:

The name for the route. If None, derived from handler name.

param **kwargs:

Additional arguments to associate with the route.

apifrom.core.router.get_route_by_path(path, method='GET')

Get a route by path and method.

param path:

The path to match.

param method:

The HTTP method to match.

returns:

The route info if found, None otherwise.

apifrom.core.router.get_route_handler(path, method='GET')

Get a route handler by path and method.

param path:

The path to match.

param method:

The HTTP method to match.

returns:

The handler function if found, None otherwise.

Functions

apifrom.core.router.get_type_hints_with_extras(obj)[source]
Parameters:

obj (Callable)

Return type:

Dict[str, Type]

Get type hints for a callable, including return type.

This function extends typing.get_type_hints to include additional information about the types, such as whether they are optional.

param obj:

The callable to get type hints for.

returns:

A dictionary mapping parameter names to their types.