HTTP Get with 204 No Content: Is that normal

后端 未结 5 645
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 10:11

Is it a normal occurrence for an HTTP GET Request to have a response with status code 204 - No Content? Like, is this semantically correct concerni

5条回答
  •  一生所求
    2021-01-30 10:58

    Your current combination of a POST with an HTTP 204 response is fine.

    Using a POST as a universal replacement for a GET is not supported by the RFC, as each has its own specific purpose and semantics.

    The purpose of a GET is to retrieve a resource. Therefore, while allowed, an HTTP 204 wouldn't be the best choice since content IS expected in the response. An HTTP 404 Not Found or an HTTP 410 Gone would be better choices if the server was unable to provide the requested resource.

    The RFC also specifically calls out an HTTP 204 as an appropriate response for PUT, POST and DELETE, but omits it for GET.

    See the RFC for the semantics of GET.

    There are other response codes that could also be returned, indicating no content, that would be more appropriate than an HTTP 204.

    For example, for a conditional GET you could receive an HTTP 304 Not Modified response which would contain no body content.

提交回复
热议问题