HTTP and Your First Server

Before a framework, the conversation it handles: a request goes in, a response comes out. Learn HTTP's parts in plain words (methods, paths, query strings, status codes, headers and bodies), send requests with VS Code's REST Client, and answer them with a server built from Node's own http module, so you can see what Express does for you.

Updated

HTTP in Plain Words

  1. HTTP in Plain Words: Requests and Responses (Apprentice): Every app that talks to a server sends an HTTP request (a method, an address, headers and sometimes a body) and gets a response back, and in Node you read a request's path and query values with URL and URLSearchParams.
  2. Status Codes and Headers (Apprentice): A response's three-digit status code tells the client how its request went before it reads a word of the body, and headers such as Content-Type tell it how to read that body.

Node's Own Web Server

  1. A Web Server with Node's http Module (Apprentice): Node's own http module starts a web server that keeps running and calls your function once for every request, which reads req.method and req.url and answers with res.writeHead and res.end.
  2. Routing by Hand, and Why Frameworks Exist (Apprentice): A node:http server routes each request with if statements on its method and path, reads a JSON body that arrives in pieces, and grows a little with every address, which is the work a framework such as Express takes over.

Exercise: Community Garden Server

  1. Exercise: Community Garden Server (Apprentice): Finish the community garden's server with Node's own http module, answering the list of plots, the free plots, one plot by its number and a JSON 404 for anything else, and let Supertest's tests check every answer.