Backbone.save POST而不是PUT [英] Backbone.save POST instead of PUT

查看:441
本文介绍了Backbone.save POST而不是PUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个简短的问题:

有一个模型的新实例,并出具了 model.save()与URL设置为 / API /存储/类别,主干发出一个POST。据我所知,它应该使用PUT,想在这个提到的PUT或POST:该故事的其余部分博客文章

Having the new instance of a model and issuing a model.save() with URL set to /api/store/category, Backbone issues a POST. According to my knowledge, it should use PUT, like mentioned in this "PUT or POST: The REST of the Story" blog post.

谁是谁非? BB或这篇文章的作者?

Who is right? BB or this article's author?

推荐答案

根据骨干文档,节省了新车型将导致POST请求,并保存现有模型(有一个id),就会发出一个PUT请求。

According to Backbone documentation, saving a new model will result in a POST request, and saving an existing model (having an id) will emit a PUT request.

保存 model.save([属性],[选项])的结果
  ...结果
  如果模型是否新款,保存将是一个创造(HTTP POST),如果模型已经
  存在于服务器上,保存将是一个更新(HTTP PUT)。

save model.save([attributes], [options])
...
If the model isNew, the save will be a "create" (HTTP POST), if the model already exists on the server, the save will be an "update" (HTTP PUT).

如果你想知道,如果骨干网的的使用POST用于创建,检查

And if you are wondering if Backbone should use a POST for creation, check


  1. PUT VS POST在REST

  2. REST Web服务维基百科

  1. PUT vs POST in REST
  2. RESTful web services on Wikipedia

在这些文章中的光,我想说的是,在骨干网的情况下,动词是正确的:

In the light of these articles, I'd say that, in the context of Backbone, the verbs are correctly used:


  • 节约的新模式导致系统发生了变化,新的URL添加,动作不幂等,它应该是一个POST,

  • 在一个给定的URL保存模型称为取代了资源,动作幂等的,它应该是一个PUT。

这篇关于Backbone.save POST而不是PUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆