- 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.
Turn to your neighbor and discuss what an HTTP server is. Be prepared to share with the class.
Turn to your neighbor and discuss why HTTP Servers are impotant. Be prepared to share with the class.
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
- Method (or verb): __________
- Path: __________
- HTTP version: __________
- Headers (pick one): __________
- Body (optional): __________
Response
- HTTP version: __________
- Status code: __________
- Headers (pick one): __________
- 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,
...
Clone this repo to try out writing some HTTP servers:
git clone https://github.com/Shurlow/http-server-lesson.git
- Start by looking through
simpleServer.js. Test it out by runningnode simpleServer.jsand sending a request tolocalhost:8000. - Update
simpleServer.jsto read fromguests.jsonfile. - Read through
server.jsand test it out. - Update
server.jsto accept GET reqests to/guests/0and respond with the first guests name.