Routing with Controllers
Controllers are the main architectural blocks of the Ascender Framework. They define the final HTTP endpoints—the tips of the router graph's branches. Controllers manage and process incoming requests, returning appropriate responses.
Sections
- Defining a Controller
- Defining Routes of a Controller
- Combining and Composing Controllers with the Router Graph
Defining a Controller
Each controller in the Ascender Framework contains the following key components:
- A @Controllerdecorator to define the controller class.
- A Python class with endpoint functions that implement the controller's endpoint behavior.
- Methods wrapped with HTTP method decorators, which define the routes and their behavior.
| user_controller.py | |
|---|---|
Defining Routes of a Controller
Routes are defined by creating methods inside the controller class and wrapping them with specific HTTP method decorators.
get_all_users method defines a route using the @Get() decorator, making it accessible as the root endpoint of the UserController.
Combining and Composing Controllers with the Router Graph
The router graph in the Ascender Framework defines routes to controllers and their endpoints. It organizes the application's routing structure into a graph where specific "Route Nodes" are tied to controllers. These route nodes contain information about the controllers' base path, OpenAPI configurations, and child nodes.
graph LR
  A[Router Graph] --> |controller| B(MainController);
  A -->|controller| C(UserController);
  C --> |GET: /| D[get_all_users];| routes.py | |
|---|---|
This example demonstrates how to define routes connecting base paths to controllers, with metadata for OpenAPI documentation and schema inclusion.
Tip
Read more about router graph and Ascender Framework routes in Controllers Overview
Tip
Want to know more about Ascender Framework's controllers? See the Controllers Overview