开发者

Should a web service have both a create and save web method?

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 c开发者_C百科reate 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜