HTTP Responses rely upon one required parts and two optional parts:
- Status Code – These are three digit codes with optional descriptive text that inform the client how the HTTP request was handled. There are standard codes but there are reasons for custom ones to be used. The code is primarily for the benefit of machines and the descriptive text is primarily for the benefit of humans. By building dependency upon standard codes, web applications can respond to various status codes in predictable ways. For instance, a 408 status code implies that the request timed out. Clients should be smart enough to resubmit a request in hopes that this was simply due to a momentary problems. Whereas a 500 status code strongly suggests a more severe problem and no automated re-submission should be attempted. The status code is always required.
- Header Fields – As with HTTP requests, HTTP responses also make use of header fields. Please see the above paragraph for a general explanation of their use. Header fields are always required.
- Body – In almost all cases an HTTP response will return some form of content, or body, but this is not a requirement. For instance, status codes that communicate an error condition might not return anything in the body and simply rely upon the code and header fields. Under normal working conditions, however, the body will contain formatted data that will be meaningful to the client (e.g., HTML, XML, PDF, Text, etc.). In the same way that HTTP requests use header fields to identify the format of the content being submitted, HTTP responses will also identify the format so the client knows how to render it.
This is also covered in more detail in the How do I prepare a response? article.