"为什么"确实骨干没有保存(PUT / POST)方法为其催收 - 是unRESTful? [英] "Why" does Backbone NOT have a save (PUT/POST) method for its collections - is it unRESTful?

查看:134
本文介绍了"为什么"确实骨干没有保存(PUT / POST)方法为其催收 - 是unRESTful?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问一个问题,而回,即如何保存整个骨干集合?。然而是什么令我着迷的是,为什么不提供一个节省​​的方法?难道unRESTful保存(PUT / POST)整个集合或者是罕见的REST的土地这样做呢?

I asked a question a while back i.e. "How save an entire backbone collection?". However what intrigues me is that why is a save method not offered? Is it unRESTful to save (PUT/POST) entire collections or is it uncommon to do so in the REST-land?

GET:  /MySite/Collections - allowed by collection.fetch()
POST: /MySite/Collections - for the model(s) in the collection to be Posted when calling model.save()
PUT:  /MySite/Collections/{id} - for the model(s) to be updated individually
GET:  /MySite/Collections/{id} - to fetch an individual model throuth model.fetch()

那么,为什么不允许POST / PUT资源的整个集合?这是方便,有时虽然可以包装/使用破解了一些code collection.toJSON 为什么不包括的呢?我只是好奇它的缺席和同样的理由。没有框架的一些事情的能力通常意味着不好的编程/设计,因此被排除在外。是节省整个集合'的坏习惯的'?

So why not allow for POST/PUT an entire collection of resources? It is convenient sometimes and although one can wrap/hack out some code using collection.toJSON why not include it? I'm just curious about its absence and the rationale for the same. Frameworks not having the capability of a few things usually implies bad programming/design and are thus left out. Is saving an entire collection 'bad practice'?

推荐答案

关于REST的维基百科的文章做的一提CRUD动词收集

The wikipedia article about REST does mention CRUD verbs for collection.

不过,在我看来,一个集合不是一种资源,它不是一个实体,它有没有状态。它,相反,一个的一堆的资源。如果存在将是一个的更新的命令集合这将是没什么,但多的更新的在多个模型命令。拥有多个的可能性的更新的只有一个请求,命令将是有益的,但​​我认为这不是对REST实现的工作。

But, in my opinion, a Collection is not a resource, it is not an entity, and it has not state. It is, instead, a bunch of resources. And if there would be an UPDATE command for a Collection it would be nothing else but a multiple UPDATE commands over multiple Models. Having the possibility of multiple UPDATE commands in only one request would be helpful but I think this is not a job for the REST implementation.

也将有包含已集合歧义的问题,例如保存的用的标识的等等,和其他模型没有,会是怎样一个 POST 的命令是什么意思?......或更新的命令?...

Also there will be problems of ambiguity, for example in a Collection that contains already saved Models with id and so on, and others that not, what will a POST command mean?... or an UPDATE command?...

没有谈论的复杂性,在服务器端的增加,其中,如果该集合REST支持应该采取类似的标准,我们应该努力实现诡辩的两倍。

No talking about the increase of the complexity in the server side where, if this Collection REST support should be taken like standard, we should to work the double to accomplish the casuistic.

总结:我没有看到一个集合REST命令的需要不能实际解决任何情况下,更简单,只-型号REST命令,所以保持事情尽可能的简单,我认为是一个很好的习惯。

Summarizing: I don't see any case where the need of a Collection REST command can't be solved with the actual, simpler, only-Model REST commands, so keeping the things as simple as possible I think is a good habit.

这篇关于"为什么"确实骨干没有保存(PUT / POST)方法为其催收 - 是unRESTful?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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