[英]MongoDB only one item, post or put?
POST to create a new item, PUT to update an item.. but what if there's only one item in the database? POST创建一个新项目,PUT更新一个项目..但是,如果数据库中只有一个项目该怎么办?
Do I code: 'if item already exists, find it and PUT' else 'POST' 我是否编码:“如果项目已经存在,找到并放置”,否则为“ POST”
or am I missing something very obvious? 还是我缺少一些非常明显的东西?
I briefly thought of doing post everytime, and on the first line of the post just delete everything, then post, but that seems dumb 我短暂地想到了每次都要进行发布,并且在发布的第一行只是删除所有内容,然后发布,但这似乎很愚蠢
Personally, I prefer to POST
for the original creation, and PATCH
for updates... 就个人而言,我更喜欢使用
POST
进行原始创建,而使用PATCH
进行更新...
PUT /myresources/:id
POST /myresources
should return a location
header with the generated path, as well as an acceptable response body. 应该返回带有生成路径的
location
标头,以及可接受的响应主体。
{
id: "someid",
location: "/myresources/someid"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.