Skip to content

Conversation

@slacmshankar
Copy link
Contributor

Add an API call for listing SSH MFA keys
Need to add some CORS for integration with coact

Need to add some CORS for integration with coact
@yee379
Copy link
Contributor

yee379 commented Nov 15, 2025

Not sure I like the idea of having a separate prefix url for /api. Can we do it the rails way and just inspect the message type and respond the same? (Ie json get returns json) Or is this rather un-pythonic?

@yee379
Copy link
Contributor

yee379 commented Dec 8, 2025

can we implement something like

from fastapi import FastAPI, Request, Depends
from enum import Enum

class ResponseType(str, Enum):
    HTML = "html"
    JSON = "json"

def get_response_type(request: Request) -> ResponseType:
    accept = request.headers.get("accept", "")
    if "text/html" in accept:
        return ResponseType.HTML
    return ResponseType.JSON

@app.get("/items")
async def get_items(response_type: ResponseType = Depends(get_response_type)):
    if response_type == ResponseType.HTML:
        return HTMLResponse("<h1>HTML</h1>")
    return {"message": "JSON"}

so we're more DRY?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants