Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

FastAPIとuvicornサーバーを使った簡易ロボットサーバー その1:環境構築

実際のところ

目標

JSONで記述されたロボットの動きを取り次ぐAPIサーバー on RasPi

ライブラリのダウンロード

pip3 install fastapi uvicorn[standard]

最小動作確認

# ownserver.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/health")
async def health_check():
    return {"status": "ok"}
実行
$ uvicorn ownserver:app --reload --host 0.0.0.0 --port 8000
動作確認
$ curl http://localhost:8000/
{"message":"Hello World"}