Test / app.py
hashimotoa961
fix for fastapi + uvicorn
ab54869
raw
history blame
718 Bytes
from fastapi import FastAPI, Query, HTTPException
from typing import Dict, Optional
import requests
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, World!"}
@app.get("/api/")
def api(endpoint: str = Query(..., alias="endpoint"), other_params: Optional[Dict[str, str]] = None):
# クライアントからのリクエストデータを取得
if not endpoint:
raise HTTPException(status_code=400, detail="No endpoint specified")
# AWS API Gatewayにリクエストを転送
print(endpoint, other_params)
response = requests.get(endpoint, params=other_params)
# AWSからのレスポンスをクライアントに返す
return response.json()