APIFuseAPIFuse
  • Providers
  • 変更履歴
  • Playground
  • ダッシュボード
  • APIFuse ドキュメント
    • はじめに
    • 認証と Connection
    • Playground
    • OpenAPI と schema
    • MCP エンドポイント
    • Developer MCP ガイド
    • スキーマバンドル
    • Next.js App Router 連携
    • FastAPI 連携
    • エラーハンドリング
    • FAQ
    • リソース
APIFuseAPIFuse

FastAPI 連携

サーバー側 FastAPI アプリケーションから APIFuse を呼び出します。

FastAPI 連携

サーバー上で実行される FastAPI route から APIFuse を使用します。APIFuse API キーはサーバー設定に保存し、受信リクエストデータと APIFuse response の両方を検証してください。

1. 型付きモデルを追加する

schema bundle の Pydantic model を使用するか、API リファレンスの operation schema に一致する model を定義します。

2. gateway を呼び出す

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:
        # すべての失敗を 1 つのステータスに潰さず、APIFuse のエラー判定を
        # (ステータスと body のバイトのまま)伝えてください。HTTPException は
        # body を {"detail": ...} の下に包み、code / retryable / source
        # フィールドを隠してしまいます。詳細はエラーハンドリングガイドへ。
        return Response(
            content=response.content,
            status_code=response.status_code,
            # アップストリームの Content-Type に関わらず JSON として返し、
            # 予期しない non-JSON body が same-origin HTML として描画されるのを
            # 防ぎます。ガイドが依存するリトライ・相関ヘッダーは保持します。
            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()

3. アプリケーションデータを返す

ブラウザまたはモバイルクライアントに返す前に、APIFuse response をプロダクトに必要なデータ形式に整えます。

On this page

FastAPI 連携1. 型付きモデルを追加する2. gateway を呼び出す3. アプリケーションデータを返す
APIFuseAPIFuse
  • Providers
  • 変更履歴
  • Playground
  • ダッシュボード
  • APIFuse ドキュメント
    • はじめに
    • 認証と Connection
    • Playground
    • OpenAPI と schema
    • MCP エンドポイント
    • Developer MCP ガイド
    • スキーマバンドル
    • Next.js App Router 連携
    • FastAPI 連携
    • エラーハンドリング
    • FAQ
    • リソース
Providers
  • API Reference
    • Amazon Japan
    • Baeminプロバイダー
    • Buyee
    • CatchTable
    • Charan Commerce
    • Daangn (Karrot)
    • Daiso 商品・店舗データ
    • Danawa 価格比較
    • Demaecan
    • 駅探
    • Goodchoice(ヨギオッテ)韓国国内宿泊
    • Google Flights
    • 漢江水位
    • ホットペッパーグルメ
    • Hyundai Card
    • Jalan
    • Japan National Diet Minutes
    • Japan Disaster Alerts
    • 日本 EDINET 開示書類
    • e-Gov法令検索
    • Japan e-Stat
    • Japan GSI Geocoding
    • Japan e-Gov Open Data
    • Japan Post ZIP
    • 日本の祝日
    • JMA Weather
    • KakaoMap
    • Kakao T タクシー配車
    • Korea Address Search
    • AirKorea 空気質
    • Korea Apartment Rent Prices
    • Korea Apartment Sale Prices
    • Korea Bid Notices
    • Korea Building Register
    • Korea Business Verify
    • Korea Camping
    • Korea DART Corporate Finance
    • DART Corporate Info
    • Korea Culture Events
    • Korea Disaster Alert
    • Korea Emergency Hospital
    • Korea ETF
    • Korea EV Charger
    • Korea Fuel Price
    • Korea Holiday
    • Korea Hospital Info
    • Korea Land Price
    • 医薬品安全情報
    • 食品安全情報
    • 生活廃棄物排出案内
    • 国家法令情報
    • 学校給食
    • 宅配追跡
    • Korea Pharmacy
    • Korea Population
    • Korea Stock Index
    • Korea Stock Price
    • Korea Train Schedule
    • KMA 天気予報
    • Korea Weather Forecast
    • Korea Welfare Service
    • K-Startup
    • LH 住宅公告
    • Market Kurly
    • Mercari
    • モドゥ駐車場(Modu Parking)
    • Naver Blog 検索
    • Naver Flight
    • Naver Map
    • Naver News 検索
    • NOL 宿泊施設
    • Ohouse
    • Rakuten Ichiba
    • Rakuten Travel
    • SEC EDGAR Filings
    • ソウル公共自転車
    • ソウル混雑度
    • ソウル地下鉄到着情報
    • Shinhan Bank
    • Shinhan Card
    • Skiplagged
    • SUUMO
    • Swing Taxi
    • Tabelog
    • TableCheck
    • Weverse プロバイダー
    • Yahoo!ショッピング(日本)
    • Yogiyo
    • ZOZOTOWN
APIFuseAPIFuse

FastAPI 連携

サーバー側 FastAPI アプリケーションから APIFuse を呼び出します。

FastAPI 連携

サーバー上で実行される FastAPI route から APIFuse を使用します。APIFuse API キーはサーバー設定に保存し、受信リクエストデータと APIFuse response の両方を検証してください。

1. 型付きモデルを追加する

schema bundle の Pydantic model を使用するか、API リファレンスの operation schema に一致する model を定義します。

2. gateway を呼び出す

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:
        # すべての失敗を 1 つのステータスに潰さず、APIFuse のエラー判定を
        # (ステータスと body のバイトのまま)伝えてください。HTTPException は
        # body を {"detail": ...} の下に包み、code / retryable / source
        # フィールドを隠してしまいます。詳細はエラーハンドリングガイドへ。
        return Response(
            content=response.content,
            status_code=response.status_code,
            # アップストリームの Content-Type に関わらず JSON として返し、
            # 予期しない non-JSON body が same-origin HTML として描画されるのを
            # 防ぎます。ガイドが依存するリトライ・相関ヘッダーは保持します。
            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()

3. アプリケーションデータを返す

ブラウザまたはモバイルクライアントに返す前に、APIFuse response をプロダクトに必要なデータ形式に整えます。

On this page

FastAPI 連携1. 型付きモデルを追加する2. gateway を呼び出す3. アプリケーションデータを返す