Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PUTとPOSTどっち使う?
Search
Hank Ehly
June 23, 2022
Technology
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PUTとPOSTどっち使う?
https://qiita.com/hankehly/items/ed7e699ebe89f14b2ff7
Hank Ehly
June 23, 2022
Transcript
18 slides
PUTとPOSTどっち使う? qiita.com/hankehly > PUTとPOSTどっち使う?
自己紹介 • Hank Ehly (ハンク イーリー) • ENECHANGE株式会社 • qiita.com/hankehly
• connpass.com/user/hankehly • github.com/hankehly • speakerdeck.com/hankehly qiita.com/hankehly > PUTとPOSTどっち使う?
アジェンダ 1. PUTとPOSTの違い 2. POST 3. PUT qiita.com/hankehly > PUTとPOSTどっち使う?
百億%忘れてい るぜ
1 0 意識している あまり意識しない チャットに投稿してください Web APIを開発する上で PUTとPOSTの違いを…
PUTとPOSTの違い qiita.com/hankehly > PUTとPOSTどっち使う?
• リクエストに同封されているデータの意図 The fundamental difference between the POST and PUT
methods is highlighted by the different intent for the enclosed representation (RFC7231) • 使い分けることで、表現力の高い、理解しやすい Web API が作れる PUTとPOSTの違い qiita.com/hankehly > PUTとPOSTどっち使う?
PUTとPOSTの違い リソース 新規作成 バッチ処理開始 データ削除 POST PUT リソース 置き換え ファイル
アップロード qiita.com/hankehly > PUTとPOSTどっち使う?
POST
POST • 受け取ったデータで何してもおかしくない • 汎用的 リクエスト レスポンス DBレコードを INSERT する
201 (Created) ファイルを削除する 204 (No Content) 非同期処理を開始する 202 (Accepted) キャッシュされたリソースにリダイレクトする 303 (See Other) qiita.com/hankehly > PUTとPOSTどっち使う? • 一般的に冪等性がないため、キャッシュの対象にならない
POST /articles HTTP/1.1 { "name": "foo", "author": "tanaka", "content": "hello
world" } HTTP/1.1 201 Created Location: http://example.com/articles/12 POST • リソースの新規作成に使うことが多い qiita.com/hankehly > PUTとPOSTどっち使う?
POST • リソースの新規作成に使うことが多い POST /articles HTTP/1.1 { "name": "foo", "author":
"tanaka", "content": "hello world" } HTTP/1.1 201 Created Location: http://example.com/articles/12 qiita.com/hankehly > PUTとPOSTどっち使う?
POST • リソースの新規作成に使うことが多い POST /articles HTTP/1.1 { "name": "foo", "author":
"tanaka", "content": "hello world" } HTTP/1.1 201 Created Location: http://example.com/articles/12 qiita.com/hankehly > PUTとPOSTどっち使う?
PUT
PUT • 対象リソースの置き換え(丸ごと) • どのリソースを置き換えるか知っている必要がある ◦ PUT /articles/12 • 冪等性
qiita.com/hankehly > PUTとPOSTどっち使う?
PUT INSERT INTO articles (id, name, author) VALUES (12, "foo",
"tanaka") ON CONFLICT (id) DO UPDATE SET name = "foo", author = "tanaka" PUTリクエストをSQLに例えたら qiita.com/hankehly > PUTとPOSTどっち使う?
PUT INSERT INTO articles (id, name, author) VALUES (12, "foo",
"tanaka") ON CONFLICT (id) DO UPDATE SET name = "foo", author = "tanaka" PUT /articles/12 HTTP/1.1 { "name": "foo", "author": "tanaka" } PUTリクエストをSQLに例えたら qiita.com/hankehly > PUTとPOSTどっち使う?
• PUTとPOSTの違いはリクエストデータ意図です • POSTは、1つの決まった使い方がなく、汎用的に活用できる ◦ 何かを「新規作成」するためによく使われる • PUTは、リソースの状態を丸ごと置き換える • 違いを意識することで、より表現力の高い
API 開発ができる まとめ qiita.com/hankehly > PUTとPOSTどっち使う? POST /articles/12 意図が曖昧(何するの?) PUT /articles/12 意図が明確になる
ご清聴ありがとうございます qiita.com/hankehly > PUTとPOSTどっち使う?
More Decks by Hank Ehly
See All by Hank Ehly
Fivetranでデータ移動を自動化する
hankehly
0
700
Celeryの紹介と本番運用のTips
hankehly
0
1.8k
ChatGPTを活用した 便利ツールの紹介
hankehly
1
1.4k
Efficient Energy Analytics with Airflow, Spark, and MLFlow
hankehly
0
440
Deferrable Operators入門
hankehly
0
830
【初心者/ハンズオン】Dockerコンテナの基礎知識
hankehly
0
630
Compositeパターン: オブジェクトの階層関係をエレガントに表現する方法
hankehly
0
380
10/29 Airflowの基礎を学ぶハンズオンワークショップ
hankehly
0
350
システム/データ品質保証のための Airflow 活用法
hankehly
0
710
Other Decks in Technology
See All in Technology
Kiro Enterprise Management: 管理者が 1 か所で決め、全員の Kiro に届ける
inariku
PRO
1
150
From vibe coding to reliable (agentic) development
jcabot
0
290
Metadata - Section 4 : MODS (Metadata Object Description Schema )
mohab1
0
150
kubellの最新データ分析環境
kubell_hr
2
280
Terraform 0 to 100:100個以上のリポジトリを常に最新にし続けるための自動化
sue445
3
1.5k
Welcome JXL!
dynamis
0
780
AI-DLCでソフトウェア開発の速さは 上がったのか?
rfdnxbro
0
180
本の挿絵に困ったから挿絵メーカーを自作した
yoshimura_datam
1
120
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
260
デザインシステムのフィードバックループをほぼ自動化した話
tongari07
0
990
自動計装なしでECSサービスをApplication Signalsに載せるまで
ota1022
2
480
認知の質も文化醸成も。数年取り組んで見えてきた技術広報のKPI設計 / Tech PR KPIs: Lessons on Awareness Quality and Culture After Several Years
bitkey
PRO
0
250
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Accessibility Awareness
sabderemane
1
310
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Agile that works and the tools we love
rasmusluckow
331
22k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
540
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
390
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
640
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
530