用于获取随机数动词的 RESTful Web 服务 [英] RESTful web service to get random number verb

查看:34
本文介绍了用于获取随机数动词的 RESTful Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您创建一个可以返回随机数的 RESTful Web 服务,您应该使用什么动词?

If you create a RESTful web service that can return random numbers, what verb should you use?

我的个人感觉是使用 POST,因为您每次都在创建一个新的随机数,但我听到了一些令人信服的使用 GET 的论据,因为您本质上是在获取随机数.

My personal feeling is use POST, because you are creating a new random number each time, but I have heard some convincing arguments for using GET, since you are essentially getting random numbers.

GET 也有被缓存的危险

GET also has the danger of being cached

推荐答案

在 REST 中,思考资源.

In REST, think resources.

如果服务只是返回随机数,那么您并没有真正创建新资源(例如新的数字生成器),因此 GET 感觉合适.

If the service is just returning random numbers then you aren't really creating a new resource (e.g a new number generator), so GET feels appropriate.

Fowler 的文章对该主题进行了很好的解释.

Fowler's article provides a good explanation on the subject.

这篇关于用于获取随机数动词的 RESTful Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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