Skip to main content

Part 2: Express.js for noobs

By May 22, 2018June 14th, 2018No Comments


1.1 HTTP in a nutshell:

  1. HTTP is the protocol used to send and receive information between a client (browser) and a server.
  2. The browser will send  a request message to the server requesting a resource which can be a webpage, images,scripts, style-sheets etc
  3. The servers responds by sending back the requested resource to the browser.
  4. This communication takes place as a  Request- Response Cycle.
  5. The communication takes place mostly over TCP/IP.
  6. HTTP is a stateless protocol, which means it does not store information about the request sent.
  7. It is a text-based protocol (more on this soon)
  8. Its responses have a status code (more on this soon).

1.2 Anatomy of a Request-Response Cycle:


[image taken from Here, highly recommended reading]


1.3  Anatomy of a request message

When you type in an address in the address bar of your browser or an IP address. The browser translates the URL into a request message with the following parts:


1. Request line:

  1.  Structured as: Request Method Name/ Request URI / HTTP-version
  2. For example:
GET /test.html HTTP/1.1

HEAD /query.html HTTP/1.0

POST /index.html HTTP/1.1

2. Request header:  Formatted as name : value pairs:


Accept: image/gif, image/jpeg

User Agent: Mozilla/4.0

Accept-language: en-us

Content-length: 33

3. A blank line that separates the header and body


4. Request body (optional):


Check out:  to view the parts of a request message

1.4 Anatomy of a response message

When the server receives the request, it will read it and a response message is structured with the following parts:


1. Status Code:

  1. Structured as: HTTP-version/ status-code/explanation of the status code
  2. For example:
HTTP/1.1 200 OK

HTTP/1.0 404 Not Found

HTTP/1.1 403 Forbidden

2. Response Header

  1. Formatted as name value pairs
  2. For example:
Content-Type: text/html
Content-Length: 100
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100

3. A blank line that separates the header and body

4. Response body : Contains the content of the web page that is being sent back to the browser to be displayed to the user. For example

<h1>Hello World!</h1>


Leave a Reply