Otworzyłem terminal w katalogu take-a-rest i uzyłem komendy npm install. Powstał nowy plik package-lock.json Etap 1: Użyłem komendy ​ npm run 01_HttpServer by uruchomić serwer W drugim terminalu połączyłem się za pomocą http (bez s) z localhostem 3000 Kod aplikacji odpowiedzialny za komunikaty:By dodać informację o czasie do odpowiedzi, zmodyfikowałem kod: Dla localhost:3000/hello: //response.send("

Anonymous message: Oh, Hi Mark!

"); response.send(`

Anonymous message: Oh, Hi Mark! The datetime is: ${Date.now()}

`); Efekt: Dla strony głównej:response.send(`

HTTP Server

Go to /hello subpage! The datetime is: ${Date.now()}

`); //response.send("

HTTP Server

Go to /hello subpage!

"); Efekt: Dodałem obsługę zapytania GET dla /time: app.get("/time", function(request, response) { printReqSummary(request); response.send(`

The datetime is: ${Date.now()}

`); }); Wynik: Zamknąłem serwer 01_HttpServer i uruchomiłem serwer 02_UrlParameters Sprawdziłem działanie:Zwracanie losowego argumentu: Do pliku app.js dodałem poniższy kod: function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // GET /X/Y/Z - return 1 of parameters app.get("/:x/:y/:z", function(request, response) { printReqSummary(request); const x = request.params.x; const y = request.params.y; const z = request.params.z; const rand = getRandomInt(0, 2); out = 0; if( rand == 0 ) out = x if( rand == 1 ) out = y if( rand == 2 ) out = z response.send(`

Random input value is: ${out}

`); }); Etap 3: Zamknąłem serwer z etapu 2. i uruchomiłem serwer 03_HttpMethods Sprawdzenie działania: Zmodyfikowałem plik app.js by dodawanie itemów było realizowane za pomocą POST a nie PUT /* PUT /item/:name -- add (put) new item to the collection */ //app.put("/item/:name", function(request, response) { app.post("/item/:name", function(request, response) { printReqSummary(request); const itemName = request.params.name; /* Is the item in collection? */ if (items.includes(itemName)) { response.send(`

Item "${itemName}" already in collection

`); } else { items.push(itemName); response.send(`

Item "${itemName}" added successfully

`); } });