Overview
Create a new @endpoint decorator for ModelAdmin classes that adds custom FastAPI routes with full configuration support, similar to the existing @action decorator but for arbitrary API endpoints.
Problem
Currently, there's no standardized way to add custom FastAPI endpoints to the admin panel beyond the @action decorator (which only supports list/row/detail actions) or manually adding routes. Users need a decorator that can register arbitrary @app.router.add_api_route() endpoints on registered models.
Use Cases
- Custom health check endpoints
- Custom export/import APIs
- Custom status/monitoring endpoints
- Any arbitrary JSON API endpoint within the admin prefix
Proposed Solution
Implement an @endpoint decorator in fastapi_admin_kit/admin/decorators.py that:
- Stores endpoint configuration on the decorated method as
_admin_endpoint attribute
- Automatically discovers and registers routes in
build_model_router() via router.add_api_route()
- Supports all FastAPI
add_api_route parameters: path, methods, tags, dependencies, status_code, response_model, etc.
- Integrates with existing RBAC via FastAPI dependencies
- Is fully backward compatible
Decorator API
from fastapi_admin_kit.admin.decorators import endpoint
class ProductAdmin(ModelAdmin):
@endpoint(
path="/health-check",
methods=["GET"],
tags=["monitoring"],
description="Health check endpoint",
permission="can_view",
)
async def health_check(self, request):
return {"status": "healthy"}
Supported Parameters
| Param |
Type |
Required |
Default |
path |
str |
Yes |
- |
methods |
list[str] |
No |
["GET"] |
tags |
list[str] |
No |
[] |
description |
str |
No |
"" |
name |
str |
No |
auto-generated |
dependencies |
list[Any] |
No |
[] |
status_code |
int |
No |
200 |
response_model |
Type[BaseModel] |
No |
None |
summary |
str |
No |
"" |
response_description |
str |
No |
"" |
Router Changes
Modify fastapi_admin_kit/router.py::build_model_router() to iterate admin methods, check for _admin_endpoint, and register routes.
Backward Compatibility
- Fully additive - doesn't break existing
@action, @column, etc.
- New endpoints opt-in via decoration
- Existing models/routes continue to work unchanged
Example Usage
# Simple endpoint
@endpoint(path="/health", methods=["GET"])
async def health_check(self, request):
return {"status": "ok"}
# With permissions
@endpoint(
path="/stats",
dependencies=[Depends(require_permission("products", "view"))],
)
async def stats(self, request):
pass
Labels
enhancement, feature-request, admin
Overview
Create a new
@endpointdecorator forModelAdminclasses that adds custom FastAPI routes with full configuration support, similar to the existing@actiondecorator but for arbitrary API endpoints.Problem
Currently, there's no standardized way to add custom FastAPI endpoints to the admin panel beyond the
@actiondecorator (which only supports list/row/detail actions) or manually adding routes. Users need a decorator that can register arbitrary@app.router.add_api_route()endpoints on registered models.Use Cases
Proposed Solution
Implement an
@endpointdecorator infastapi_admin_kit/admin/decorators.pythat:_admin_endpointattributebuild_model_router()viarouter.add_api_route()add_api_routeparameters:path,methods,tags,dependencies,status_code,response_model, etc.Decorator API
Supported Parameters
pathstrmethodslist[str]["GET"]tagslist[str][]descriptionstr""namestrdependencieslist[Any][]status_codeint200response_modelType[BaseModel]Nonesummarystr""response_descriptionstr""Router Changes
Modify
fastapi_admin_kit/router.py::build_model_router()to iterate admin methods, check for_admin_endpoint, and register routes.Backward Compatibility
@action,@column, etc.Example Usage
Labels
enhancement, feature-request, admin