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
16k
たのしい 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.4k
すっきり分かる Python のログ
pistatium
6
2.8k
Other Decks in Programming
See All in Programming
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.2k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
CSC509 Lecture 13
javiergs
PRO
0
110
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
990
Quine, Polyglot, 良いコード
qnighy
4
650
CSC509 Lecture 12
javiergs
PRO
0
160
Realtime API 入門
riofujimon
0
150
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Scaling GitHub
holman
458
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How GitHub (no longer) Works
holman
310
140k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
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!