REST-获取随机数GET或POST? [英] REST - get a random number GET or POST?
问题描述
如何在REST中正确实现随机数生成器?
How should a random number generator properly be implemented in REST?
GET RANDOM/
或..
POST RANDOM/
服务器每次都返回一个不同的随机数.
The server returns a different random number each time.
我可以看到两种方法的参数.
I can see arguments for both ways.
推荐答案
我要说的是,这与包含当前时间的返回页面相同-其中许多都是使用GET完成的.抽象来说,获取服务器状态的随机数(或时间)不会改变-时间和随机数都可以描述为对外部事件的观察.例如. http://random.org 使用大气噪声.
I'd say this is the same as for a page returned that contains the current time - and many of these are done using GET. Abstractly, fetching a random number (or time) the server's state doesn't change - both time and random numbers can be described as an observation of an external event. E.g. http://random.org use atmospheric noise.
GET似乎最合适,尽管需要通过适当的标头来禁用缓存,例如
GET seems most appropriate, although caching will need to be disabled via appropriate headers, e.g.
Expires: <Current Time>
Last-Modified: <Current Time>
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
如果您要确保所提供的内容已经过期:
If you want to ensure that the served content is already expired:
将响应标记为已 过期",原始服务器发送 到期日期等于日期 标头值. (请参阅规则 本节中的到期日计算 13.2.4.)
To mark a response as "already expired," an origin server sends an Expires date that is equal to the Date header value. (See the rules for expiration calculations in section 13.2.4.)
- http://www.w3.org/Protocols/rfc2616/rfc2616- sec14.html
- http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
这篇关于REST-获取随机数GET或POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!