|
1 |
| -## This week homework |
2 |
| - |
3 |
| -Assignment: |
4 |
| -Create a http server that listens to requests |
5 |
| -http://localhost:8080/status --> |
6 |
| -http://localhost:8080/add --> |
7 |
| -http://localhost:8080/subtract --> |
8 |
| - |
9 |
| -Reading |
10 |
| -Callbacks |
11 |
| -modules, require |
12 |
| -http, http listen |
| 1 | +This week's homework |
| 2 | + |
| 3 | +## Assignment: |
| 4 | +Create a http server that can add and subtract from a number, which we will call the "state". Please see in `index.js` in this folder as starting material. Pay extra attention to line 21, which contains some hints for this week `console.log('New http request received', request.url);` |
| 5 | + |
| 6 | +Rule 1: DO NOT USE EXPRESS.JS |
| 7 | +Rule 2: you can use other packages, but you HAVE to also make a version WITHOUT any NPM packages (http, of course, is not NPM but a node native package) |
| 8 | +``` |
| 9 | +// The state |
| 10 | +var state = 10; |
| 11 | +``` |
| 12 | + |
| 13 | +Endpoints criteria |
| 14 | +``` |
| 15 | +// /state |
| 16 | +// response: the current state in a html format |
| 17 | +// when the server starts, this should return "10" |
| 18 | +http://localhost:8080/state |
| 19 | +
|
| 20 | +// /add |
| 21 | +// Response: "ok" in html format |
| 22 | +// This should add 1 to the current state |
| 23 | +http://localhost:8080/add |
| 24 | +
|
| 25 | +// /remove |
| 26 | +// Response: "ok" in html format |
| 27 | +// This should subtract 1 ƒrom the current state |
| 28 | +http://localhost:8080/subtract |
| 29 | +
|
| 30 | +// /reset |
| 31 | +// Response: "ok" in html format |
| 32 | +// This should set the state back to 10 |
| 33 | +http://localhost:8080/subtract |
| 34 | +``` |
| 35 | + |
| 36 | +## Reading |
| 37 | +### Callbacks: |
| 38 | +Video: https://www.youtube.com/watch?v=pTbSfCT42_M |
| 39 | +Read: http://callbackhell.com/ |
| 40 | + |
| 41 | +### Require/exporting |
| 42 | +Video: https://www.youtube.com/watch?v=e1Ln1FrLvh8 |
| 43 | +Read: http://openmymind.net/2012/2/3/Node-Require-and-Exports/ |
| 44 | + |
| 45 | +### http, http listen |
| 46 | +Video basic: https://www.youtube.com/watch?v=pYOltVz7kL0 |
| 47 | +Video routing: https://www.youtube.com/watch?v=_D2w0voFlEk (please focus on request.url, not request.method) |
| 48 | +Read: -- |
| 49 | +Read Advanced: -- |
| 50 | + |
13 | 51 | refresh on command line
|
| 52 | +Video Mac/linux: |
| 53 | +Video PC: -- () |
0 commit comments