Web 服务是否应该同时具有创建和保存 Web 方法?
我正在为应用程序创建一个新的 Web 服务,目前正在为每个服务设计 Web 方法。我注意到,在我的情况下,创建和保存之间没有真正的区别,只是保存需要 ID 而创建不需要。
Java 服务 API 两者兼而有之。
取消 create 方法并重载 save 方法是否是一个好习惯,以便在 ID 丢失时创建新实体?这会让该网络服务的客户更容易使用吗?还是更难?
I am creating a new web service for an application and am currently designing the web methods for each service. I have noticed that there is no real different in my case between create and save except that save requires an ID and create does not.
The Java services API has both.
Is it a good practice to nix the create method and overload the save method such that if the ID is missing a new entity is created? Would this make it easier for clients of this web service? or harder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说这取决于您的网络服务和数据创建/更新的含义:
我经常看到 API 有两种不同的方法;但我经常使用只有一个的库......
我想这是因为,在这些情况下,在 API 级别上,创建与更新很重要 - 而在较低级别(即数据存储) 这并不重要。
I would say it depends on what your webservice, and data creation/update, mean :
I've often seen API that have two distinct methods ; but I've often used libraries that only have one...
I suppose it's because, in those situations, on the API level, creating vs updating matters -- while on a lower level (i.e. data-storage) it doesn't matter much.
对于我使用过的大多数 Web API,它们在界面中将创建与更新分开。
框架似乎将这些结合起来。
因此,我想说,在服务器端,将它们组合起来使您的编码更容易,但在 API 中将它们分开。
For most web APIs that I've used, they've separated Create from Update in their interfaces.
Frameworks seem to combine these.
So, I'd say, on the server side, combine them to make your coding easier, but keep them separate in the API.