HTTP response

Basically, a HTTP response is a message that a HTTP server creates in respond to a HTTP request sent by a HTTP client.

For example, when you access the Python 3 Flask MVP that we had discussed earlier, your browser sends a HTTP request to Flask. In return, Flask creates the following HTTP response back to your browser:

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 24
Server: Werkzeug/0.14.1 Python/3.6.5
Date: Sun, 23 Sep 2018 07:51:44 GMT

Hello there, I am a MVP!

As shown above, a typical HTTP response includes the following:

  • The protocol version that this response was created with (HTTP/1.1)
  • The status with regards to the request that was received (200 OK)
  • The type of content that this response contains (Content-Type: text/html; charset=utf-8)
  • The size of this content (Content-Length: 24)
  • The HTTP server information (Server: Werkzeug/0.14.1 Python/3.6.5)
  • The date which this response was created (Date: Sun, 23 Sep 2018 07:51:44 GMT)
  • The content that was requested for (Hello there, I am a MVP!)

As can be seen, the content was included after 2 line breaks. In addition, the content portion can be empty if the status is not 200 OK.

Generally, for a dynamic website, we create codes that generates different HTTP responses for each URL. On the other hand, for a static website, we tend to configure ready-made HTTP servers to help us create HTTP responses for static resources.