TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

PUT vs POST in REST

127 点作者 zengr超过 13 年前

8 条评论

ericmoritz超过 13 年前
With POST you're creating a resource within the resource identified by the Request-URI. The server is responsible for creating a URI for the new resource you created.<p><pre><code> POST /forum/http/ - creates a new post into the HTTP forum POST /photogalleries/cats/ - uploads a new photo into the cats photo gallery </code></pre> With PUT the client knows the resource's URI. The client uses it to create or update the resource. The easiest why to visualize this is to think of a filesystem<p><pre><code> PUT /forum/http/post-vs-put - upserts a post identified by "post-vs-put" into the HTTP forum PUT /photogalleries/cats/smelly-cat - upserts a photo identified by "smelly-cat" into the cat's photo gallery.</code></pre>
评论 #3147369 未加载
ericmoritz超过 13 年前
I've often thought of creating a "Cult of HTTP" that goes door to door and hands out pamphlet versions of Chapter 8 of "RESTful Web Services" to web developers.<p><a href="http://my.safaribooksonline.com/book/web-development/web-services/9780596529260/rest-and-roa-best-practices/bestpractices#X2ludGVybmFsX0ZsYXNoUmVhZGVyP3htbGlkPTk3ODA1OTY1MjkyNjAvMjE1" rel="nofollow">http://my.safaribooksonline.com/book/web-development/web-ser...</a>
评论 #3146445 未加载
评论 #3146939 未加载
gurraman超过 13 年前
This was a nice take-away for me: "PUT is idempotent".
评论 #3145923 未加载
simondlr超过 13 年前
I think either way is okay. It depends on how you want to structure it. Most web APIs aren't entirely RESTful anyway. It is also important to note that a lot of hosting providers don't support other verbs than GET or POST (ie Low-REST) [1].<p>[1] <a href="http://www2008.org/papers/pdf/p805-pautassoA.pdf" rel="nofollow">http://www2008.org/papers/pdf/p805-pautassoA.pdf</a>
lhnz超过 13 年前
1. What do you do if you wish to hide a query from the HTTP access log? Normally I would use POST rather than GET, but if I wish to make my API restful I have to ensure that POST is for create, and GET is for read.<p>2. Does PUT data also not appear in the HTTP access log?<p>3. What do you gain from doing everything this way? There are a lot of developers that won't have any idea what all of these HTTP request codes and methods actually are.
评论 #3146426 未加载
评论 #3146798 未加载
piggity超过 13 年前
And once you've agreed on PUT vs POST, you can start the arguments on PUT vs PATCH !<p><a href="https://github.com/rails/rails/issues/348" rel="nofollow">https://github.com/rails/rails/issues/348</a>
arunoda超过 13 年前
I would love to match curd with rest and I dnt find any ptoblems after that.<p>Create - Put, Update - Post, Retrieve - Get, Delete - Delete
评论 #3146244 未加载
评论 #3145954 未加载
manojlds超过 13 年前
Old questions in SO, generate interest in HN? Isn't N supposed to be NEWS?
评论 #3145716 未加载
评论 #3145733 未加载