FastAPIでHello World
FastAPIと一緒にlive serverであるUvicornを使用する。 インストールするパッケージ一覧を作成する。
code:requirements.txt
fastapi
uvicorn
仮想環境をアクティベートした状態で以下のとおりインストール。
code:shell
pip install -r requirements.txt
ちなみに個別にインストールしてもいい。
code:shell
pip install fastapi
pip install uvicorn
uvicorn --version
Hello Worldコード。
code:main.py
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def root():
return "Hello World!"
サーバーを起動。
code:shell
uvicorn main:app --reload
https://gyazo.com/bd33aeba9135401e1bfa5dc6eac9c08c
https://gyazo.com/dabfad3132ee7d845cf7843b30ec79f8