Guides
Call APIFuse from a server-side FastAPI application.
Use APIFuse from FastAPI routes that run on your server. Store the APIFuse API key in server configuration and validate both incoming request data and APIFuse responses.
Use Pydantic models from a schema bundle, or define models that match the operation schema from the API reference.
import os
import httpx
from fastapi import APIRouter, Response
router = APIRouter()
@router.post("/places")
async def places(input_payload: dict) -> dict | Response:
api_key = os.environ["APIFUSE_API_KEY"]
async with httpx.AsyncClient(timeout=15.0) as client:
response = await client.post(
"https://api.apifuse.com/v1/kakaomap/search",
headers={"Authorization": f"Bearer {api_key}"},
json=input_payload,
)
if response.status_code >= 400:
# Preserve the APIFuse error verdict (status and body bytes) instead
# of collapsing every failure into one status. HTTPException would
# nest the body under {"detail": ...} and hide the code / retryable /
# source fields documented in the Error Handling guide.
return Response(
content=response.content,
status_code=response.status_code,
# Serve as JSON regardless of upstream Content-Type so an
# unexpected non-JSON body can never render as same-origin HTML;
# keep the retry and correlation headers the guide relies on.
media_type="application/json",
headers={
key: value
for key, value in {
"Retry-After": response.headers.get("retry-after"),
"X-Request-Id": response.headers.get("x-request-id"),
}.items()
if value is not None
},
)
return response.json()Shape the APIFuse response into the data your product needs before returning it to browser or mobile clients.