|
from fastapi import FastAPI, HTTPException |
|
from pydantic import BaseModel |
|
|
|
class GreetingResponse(BaseModel): |
|
Hello: str |
|
|
|
app = FastAPI() |
|
|
|
@app.get("/", response_model=GreetingResponse) |
|
async def greet_json() -> GreetingResponse: |
|
try: |
|
return GreetingResponse(Hello="World!") |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
@app.get("/health") |
|
async def health_check(): |
|
return {"status": "healthy"} |
|
from fastapi import FastAPI |
|
|
|
app = FastAPI() |
|
|
|
@app.get("/") |
|
def greet_json(): |
|
return {"Hello": "World!"} |