Upgrade to Pro — share decks privately, control downloads, hide ads and more …

たのしい FastAPI

たのしい FastAPI

社内勉強会用につくった FastAPI の布教資料です。
書けなかった内容は改めて会社ブログに書く予定です。

kimihiro_n

May 08, 2020
Tweet

More Decks by kimihiro_n

Other Decks in Programming

Transcript

  1. FastAPI Ͱ HelloWorld from fastapi import FastAPI app = FastAPI()

    @app.get("/") def hello(): return {"Hello": "World"} $ pip install fastapi uvicorn $ uvicorn main:app --reload ref. https://fastapi.tiangolo.com/
  2. FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import

    BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world")
  3. FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import

    BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") ϨεϙϯεͷܕΛఆٛ
  4. FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import

    BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") View ͷϨεϙϯε͕ ͜ͷܕͰ͋Δ͜ͱΛએݴ
  5. FastAPI Ͱ ܕΛ͚ͭΔ from fastapi import FastAPI from pydantic import

    BaseModel app = FastAPI() class Response(BaseModel): hello: str @app.get("/", response_model=Response) def hello(): return Response(hello="world") σʔλΛೖΕͯ ͦͷ··ฦ͢
  6. • router ʹΑΔ View ϑΝΠϧ෼ׂ • asyncio ʹΑΔඇಉظॲཧ • middleware

    Ͱڞ௨ͷॲཧΛ௥Ճ • Dependency ʹΑΔґଘ஫ೖ • 200 Ҏ֎ͷϨεϙϯεͷఆٛ ॻ͚ͳ͔ͬͨ͜ͱ ଓ͖͸ Web Ͱ(Ծ)