-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I want to write a simple healthcheck endpoint with pydantic and call it using htmx. The endpoint returns a pydantic model. However, if I want to run the endpoint, I get: "AttributeError: 'dict' object has no attribute 'encode'. I have to manually convert the model to a dictionary using model_dump to solve this problem.
Here is the sourcecode:
FastAPI endpoint:
@router.get("/health", response_model=HealthcheckResult)
async def health_check():
result = HealthcheckResult(passed_all_checks=True)
return result
htmx wrapper:
@router.get("/health", response_class=HTMLResponse)
@htmx("health", "index", health_check)
async def health_check_htmx(
request: Request,
):
pass
pydantic model:
`class` HealthcheckResult(BaseModel):
passed_all_checks: bool
hf-kklein and ser
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request