I'm dealing with a REST API and have this question, when a request is scheduled for further processing we should return 202, when a request has no response body we should return 204. What should we do when a request will be in processing further, but has no response body either?
问题:
回答1:
That would be a 202. There is no response body after the processing is complete (and successful).
If there is no way for it to fail, or the client doesn't care about failure, and the client doesn't care when the action is complete, then 204 would be appropriate as there's no point in delaying it.
回答2:
Here are few links which goes into more detail:-
Restful API Design: Asynchronous Requests
RFC 7231 Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content - Section 6.3.3 - Accepted 202
HTTP Status Codes
回答3:
Why are you not returning a response body for a 202? According to the spec:
The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
You can choose to not have a verbose response, but this would not change the proper response status code.