Is it wrong to return 202 “Accepted” in response to HTTP GET?

后端 未结 4 1407
遇见更好的自我
遇见更好的自我 2020-12-02 16:24

I have a set of resources whose representations are lazily created. The computation to construct these representations can take anywhere from a few milliseconds to a few hou

4条回答
  •  借酒劲吻你
    2020-12-02 17:09

    From what I can recall - GET is supposed to return a resource without modifying the server. Maybe activity will be logged or what have you, but the request should be rerunnable with the same result.

    POST on the other hand is a request to change the state of something on the server. Insert a record, delete a record, run a job, something like that. 202 would be appropriate for a POST that returned but isn't finished, but not really a GET request.

    It's all very puritan and not well practiced in the wild, so you're probably safe by returning 202. GET should return 200. POST can return 200 if it finished or 202 if it's not done.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

提交回复
热议问题