APIFuse

FastAPI integration

Call APIFuse from a server-side FastAPI application.

FastAPI integration

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.

1. Add typed models

Use Pydantic models from a schema bundle, or define models that match the operation schema from the API reference.

2. Call the gateway

import os

import httpx
from fastapi import APIRouter, HTTPException

router = APIRouter()


@router.post("/places")
async def places(input_payload: dict) -> dict:
    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:
        raise HTTPException(status_code=502, detail="apifuse_request_failed")

    return response.json()

3. Return application data

Shape the APIFuse response into the data your product needs before returning it to browser or mobile clients.