Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
距離関数を極める! / SESSIONS 2024
gam0022
0
360
Symfony Mapper Component
soyuka
2
340
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
1.1k
Cognitoが大型アップデート!Managed Loginとパスワードレスログインを実際に使ってみた@しむそくRadio Special Day1
tmhirai
3
180
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
10
4.1k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
150
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
120
[KR] Open-Source Ecosystems
skydoves
0
110
Cursorでアプリケーションの追加開発や保守をどこまでできるか試したら得るものが多かった話
drumnistnakano
0
260
flutterkaigi_2024.pdf
kyoheig3
0
440
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
230
似たもの同士のPerlとPHP
uzulla
1
110
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Agile that works and the tools we love
rasmusluckow
328
21k
What's in a price? How to price your products and services
michaelherold
243
12k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Why Our Code Smells
bkeepers
PRO
334
57k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
880
The World Runs on Bad Software
bkeepers
PRO
65
11k
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!