Web 服务是否应该同时具有创建和保存 Web 方法?

发布于 2024-09-06 07:58:56 字数 201 浏览 2 评论 0原文

我正在为应用程序创建一个新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪 2024-09-13 07:58:56

我想说这取决于您的网络服务和数据创建/更新的含义:

  • 如果创建记录和更新记录对于您和您的用户来说是两件完全不同的事情,那么您应该有两种方法:这可能会变得更有意义。
  • 如果最重要的是保存数据,那么,您可以只使用一个。

我经常看到 API 有两种不同的方法;但我经常使用只有一个的库......

我想这是因为,在这些情况下,在 API 级别上,创建与更新很重要 - 而在较低级别(即数据存储) 这并不重要。

I would say it depends on what your webservice, and data creation/update, mean :

  • If creating a record, and updating a record, are two really different things for you and your users, then, you should have two methods : this will probably be more meaningful.
  • If what matters the most is that the data is saved, then, you could use only one.

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.

追我者格杀勿论 2024-09-13 07:58:56

对于我使用过的大多数 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文