Skip to content

Instantly share code, notes, and snippets.

@Shurlow
Last active July 18, 2017 14:42
Show Gist options
  • Select an option

  • Save Shurlow/a6d746d0dd7838c676f4cc948e6a007f to your computer and use it in GitHub Desktop.

Select an option

Save Shurlow/a6d746d0dd7838c676f4cc948e6a007f to your computer and use it in GitHub Desktop.
HTTP Server Instructor Notes

HTTP Server Instructor Notes

Objectives

  • Explain what an HTTP server is.
  • Explain why an HTTP server is important.
  • Explain what an HTTP request and response is.
  • Create a Node.js HTTP server that performs asynchronous file I/O operations.

Explain What an HTTP Server is

Turn to your neighbor and discuss what an HTTP server is. Be prepared to share with the class.

Explain why an HTTP server is important

Turn to your neighbor and discuss why HTTP Servers are impotant. Be prepared to share with the class.

Explain what an HTTP request and response is.

Lets make an HTTP request to this endpoint:

http -v 'http://api.fixer.io/latest?base=USD'

(The -v flag tells HTTPie to print both the outgoing request and the incoming response and body)

Looking at the output from the above command, fill in the following parts of the request and response.

Request

  1. Method (or verb): __________
  2. Path: __________
  3. HTTP version: __________
  4. Headers (pick one): __________
  5. Body (optional): __________

Response

  1. HTTP version: __________
  2. Status code: __________
  3. Headers (pick one): __________
  4. Body: __________
GET /latest?base=USD HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: api.fixer.io
User-Agent: HTTPie/0.9.8


HTTP/1.1 200 OK
Cache-Control: public, must-revalidate, max-age=900
Connection: keep-alive
Content-Length: 447
Content-Type: application/json
Date: Mon, 17 Jul 2017 20:31:15 GMT
Last-Modified: Mon, 17 Jul 2017 00:00:00 GMT
Server: nginx/1.11.13
Vary: Origin
X-Content-Type-Options: nosniff

{
    "base": "USD",
    "date": "2017-07-17",
    "rates": {
        "AUD": 1.277,
        "BGN": 1.7063,
        "BRL": 3.1789,
        "CAD": 1.2652,
        "CHF": 0.96074,
        "CNY": 6.7694,
        "CZK": 22.762,
        "DKK": 6.488,
...

Create a Node.js HTTP server that performs asynchronous file I/O operations.

Clone this repo to try out writing some HTTP servers:

git clone https://github.com/Shurlow/http-server-lesson.git
  1. Start by looking through simpleServer.js. Test it out by running node simpleServer.js and sending a request to localhost:8000.
  2. Update simpleServer.js to read from guests.json file.
  3. Read through server.js and test it out.
  4. Update server.js to accept GET reqests to /guests/0 and respond with the first guests name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment