Implementation:24kchengYe MemoMind HttpExtension
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Extensibility |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
HTTP extension interface for adding custom API endpoints under the /ext/ path prefix without modifying the core FastAPI application.
Description
The HttpExtension ABC allows extensions to provide a FastAPI `APIRouter` that gets mounted on the main application under `/ext/`. Extensions have full control over routes, request/response models, and handlers. The memory engine is passed to `get_router()` for database operations. Configure via `HINDSIGHT_API_HTTP_EXTENSION`.
Usage
Subclass this when building an extension that adds custom HTTP endpoints (e.g., billing dashboards, admin panels, integration webhooks).
Code Reference
Source Location
- Repository: MemoMind
- File: engine/hindsight_api/extensions/http.py
- Lines: L1-101
Signature
class HttpExtension(Extension, ABC):
@abstractmethod
def get_router(self, memory: MemoryEngine) -> APIRouter: ...
Import
from hindsight_api.extensions.http import HttpExtension
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| memory | MemoryEngine | Yes | Engine instance for DB operations |
Outputs
| Name | Type | Description |
|---|---|---|
| get_router() returns | APIRouter | FastAPI router mounted under /ext/ |
Usage Examples
Adding Custom Endpoints
from fastapi import APIRouter
from hindsight_api.extensions import HttpExtension
class MyHttpExtension(HttpExtension):
def get_router(self, memory):
router = APIRouter()
@router.get("/hello")
async def hello():
return {"message": "Hello from extension!"}
@router.post("/custom/{bank_id}/action")
async def custom_action(bank_id: str):
pool = await memory._get_pool()
# ... custom logic
return {"status": "ok"}
return router