Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
たのしい FastAPI
Search
kimihiro_n
May 08, 2020
Programming
1
17k
たのしい FastAPI
社内勉強会用につくった FastAPI の布教資料です。
書けなかった内容は改めて会社ブログに書く予定です。
kimihiro_n
May 08, 2020
Tweet
Share
More Decks by kimihiro_n
See All by kimihiro_n
サービスへの影響を抑えてデータベースの移行を実施したはなしAurora MySQL -> Cloud SQL
pistatium
0
1.2k
新しいメンバーに Make debut してもらいやすくするための開発体制 with Python
pistatium
1
3.5k
すっきり分かる Python のログ
pistatium
6
2.9k
Other Decks in Programming
See All in Programming
Honoとフロントエンドの 型安全性について
yodaka
7
1.3k
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
150
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
動作確認やテストで漏れがちな観点3選
starfish719
6
1k
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
120
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
570
SwiftUI Viewの責務分離
elmetal
PRO
1
240
ソフトウェアエンジニアの成長
masuda220
PRO
12
1.7k
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
130
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
Unity Android XR入門
sakutama_11
0
160
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
Featured
See All Featured
A designer walks into a library…
pauljervisheath
205
24k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Rails Girls Zürich Keynote
gr2m
94
13k
Fireside Chat
paigeccino
34
3.2k
Designing for humans not robots
tammielis
250
25k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
9
450
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Navigating Team Friction
lara
183
15k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Transcript
ͨͷ͍͠ രͰͭ͘ΕͯɺAPI༷ॻʹͳΔʂ @kimihiro_n 3μΠδΣετ൛
Hello FastAPI
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/
Hello World
FastAPIͷԿ͕͏Ε͍͔͠ • FlaskʹࣅͨγϯϓϧͳViewఆٛ • ϗοτϦϩʔυରԠ • ϦΫΤετɾϨεϙϯεͷܕఆٛ • υΩϡϝϯτࣗಈੜ •
ඇಉظ(asyncio)ରԠ
FastAPI Ͱܕఆٛ
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")
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") ϨεϙϯεͷܕΛఆٛ
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 ͷϨεϙϯε͕ ͜ͷܕͰ͋Δ͜ͱΛએݴ
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") σʔλΛೖΕͯ ͦͷ··ฦ͢
ܕఆٛͰԿ͕ى͜Δͷ͔ • ࣙॻΛ͔ͭΘͳ͍҆શͳίʔσΟϯά • ϨεϙϯεͷܕͷνΣοΫ ◦ ܕ͕Ϛον͠ͳ͍߹Τϥʔʹ ◦ ͪΖΜϦΫΤετͷόϦσʔγϣϯ •
API υΩϡϝϯτө
API ఆٛͷࣗಈੜ
• APIͷୟ͖ํ͕Θ͔Βͳ͍ • APIఆٛͱϨεϙϯε͕߹ͬͯͳ͍ • ࠷৽ͷ༷ʹैͯ͠ͳ͍ • OpenAPI(Swagger)ͷYAML ਓྨ͕ॻ͘ͷ͡Όͳ͍ อक͕େม
APIυΩϡϝϯτͷΈ
Ͱ FastAPIͳΒ…ʁ
/doc ΞΫηε
OpenAPI ͷ༷ॻ͕ࣗಈੜ • ༷ͱ࣮͕ৗʹಉظ ◦ લड़ͷ௨ΓܕνΣοΫ͋ΔͷͰ҆৺ • SwaggerUI ্ͰAPIୟ͍ͯಈ࡞֬ೝͰ͖Δ •
ຊ൪ڥͰແޮԽ͢Δ͜ͱՄೳ
ຊʹඞཁͩͬͨͷ
• router ʹΑΔ View ϑΝΠϧׂ • asyncio ʹΑΔඇಉظॲཧ • middleware
Ͱڞ௨ͷॲཧΛՃ • Dependency ʹΑΔґଘೖ • 200 Ҏ֎ͷϨεϙϯεͷఆٛ ॻ͚ͳ͔ͬͨ͜ͱ ଓ͖ Web Ͱ(Ծ)
ThankYou!