REST - get a random number GET or POST?

后端 未结 3 1751
梦毁少年i
梦毁少年i 2021-02-14 10:36

How should a random number generator properly be implemented in REST?

GET   RANDOM/

or..

POST  RANDOM/

The se

3条回答
  •  爱一瞬间的悲伤
    2021-02-14 11:14

    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 seems most appropriate, although caching will need to be disabled via appropriate headers, e.g.

    Expires: 
    Last-Modified: 
    Cache-Control: no-cache, must-revalidate
    Pragma: no-cache
    

    If you want to ensure that the served content is already expired:

    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

提交回复
热议问题