Meg Smith
Meg Smith

Reputation: 1

HTTP Response Objects

Does every HTTP request need to be paired with a response? When you do some POST or DELETE actions, my understanding is that sometimes you don't need to send back data. I've always been told to send back an empty object, but is that necessary? Also, is sending a status code considered a response?

Upvotes: 0

Views: 695

Answers (1)

shaochuancs
shaochuancs

Reputation: 16226

Q1: Does every HTTP request need to be paired with a response?

Yes, unless client cancel the request. Actually, one HTTP request needs to be paired with one or more HTTP responses. According to RFC7231:

A server listens on a connection for a request, parses each message received, interprets the message semantics in relation to the identified request target, and responds to that request with one or more response messages.

Q2: When you do some POST or DELETE actions, my understanding is that sometimes you don't need to send back data. I've always been told to send back an empty object, but is that necessary?

It's NOT necessary to send back an empty object (payload). According to RFC7230, the response payload is not required:

A server responds to a client's request by sending one or more HTTP response messages, each beginning with... and finally a message body containing the payload body (if any).

However, although you don't have to "send back data", you still need to send back message, such as HTTP response statuc code and some necessary response headers.

Q3: is sending a status code considered a response?

Yes. Theoretically, a minimal HTTP response can only include HTTP protocol version, status code and status code textual phrase.

Upvotes: 1

Related Questions