Learning Materials
You continue watching this video. This week, you watch from 3:40:48 of the video to 6:10:46. This section of the video starts with some slides on how the web works. You do not need to write any code for these slides. Then, at about 3:56 of the video, the instructor starts talking about how you download the repository containing the code. Do not do this. You already have the code you need, as it is included in the same repository you are using. The instructor also directs you to remove the .git directory. Do not remove the .git directory. Because you forked the original repository, you continue to use the git configuration. The useful parts of the video resume about 3:58.
At about 5:18:13 of the video, the instructor discusses APIs compared with Server Side Rendering. Server Side Rendering is covered towards the end of this course. This section of the course focuses on simple responses, serving static files, and developing APIs. The APIs you develop in this class are built according to an approach called REST, which stands for Representational State Transfer. In addition, the implementation this class teaches for REST uses HTTP requests:
- Get
- Post
- Put
- Patch
- Delete
Each operation goes to a particular URL, and there may be parameters in the URL as is explained in the lesson. In addition, the POST, PUT, and PATCH operations may convey JSON data in the body of the request. JSON data is returned from the server in the body of the response. (It is possible to write APIs that don’t use JSON, but in this class JSON is always used.) If you need to learn or review JSON, a basic introduction is at this link: https://www.digitalocean.com/community/tutorials/an-introduction-to-json
The instructor again follows the pattern that he does the work in app.js and periodically copies it to one of these other names. Then he deletes it from app.js. It is not always clear when he is doing the copy operation. If you get mixed up, the answers are in the 02-express-tutorial/final directory — but try to do your own work.
Assignments
Coding Assignment
For this lesson, you switch to a different directory. You do your work in the node-express-course/02-express-tutorial directory. As usual, you should use git to switch to a new branch, the week3 branch, before you start your work.
Reminder: at about 3:56 of the video, the instructor starts talking about how you download the repository containing the code. Do not do this. The instructor also directs you to remove the .git directory. Do not remove the .git directory.
Observe what the instructor does and duplicate his work in the 02-express-tutorial directory. Be sure that you run npm install in that directory before you start writing code. You create the following files:
- 01-http-basics.js
- 02-http-app.js
- 03-express-basics.js
- 04-express-app.js
- 05-express-all-static.js
- 06-basic-json.js
- 07-params-query.js
Additional Assignment: Serving a Static File
Within the 02-express-tutorial directory, create a folder called new-public. Within that folder, create an index.html that just has an h1 element saying “Welcome to Express!”. Then, within the 02-express-tutorial directory, create a file, practiceExpress.js. Add the code to make this file a working express server. For the ‘/’ get request, it should return the index.html from the new-public folder. For the ‘/sample’ get request, it should just return the line “This is working.” Configure it to use port 3000. Test it by trying “localhost:3000” and “localhost:3000/sample” from your browser.
Mindset Assignment
Your mindset assignment for this week can be found here: Curiosity to Learn
Submitting Your Work
When you are done, do the following, use the same procedure as for previous lessons. You do a git add, git commit, and git push for the week3 branch, create your pull request on github, and put a link to your pull request in your assignment submission form below.
When you’ve completed your Coding Assignment and Mindset Assignment this week, submit all of your work using:
Alpaca class use: | Squibby 2.0 Assignment Submission Form |
Baboon and any 2023 classes use: | Homework Assignment Submission Form |