Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f08f150

Browse files
author
Noer Paanakker
committed
rewrote homework/readings all weeks
1 parent 82dab89 commit f08f150

File tree

5 files changed

+204
-103
lines changed

5 files changed

+204
-103
lines changed

week2/MAKEME.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,24 @@ This week's homework we will expand on that, in 2 parts:
205205

206206
Since we've already loaded in our package `express-handlebars`, we can get started immediately. If at any point you're stuck, try reading the [documentation](https://github.com/ericf/express-handlebars) or ask a question in Slack!
207207

208-
1. We first have to make Express aware of the templating engine. We do this by using the `engine()` and `set()` functions. Paste in the following (and figure out what it does):
208+
1. We first have to make Express aware of the templating engine. We do this by using the `engine()` and `set()` functions. Paste in the following (and figure out what it does, by checking the [documentation](https://github.com/express-handlebars/express-handlebars)):
209209

210210
```js
211211
app.set('view engine', 'handlebars');
212-
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
212+
app.engine('handlebars', exphbs({ defaultLayout: false }));
213213
```
214214

215-
2. In the root of the project folder, create a new folder called `views`. Inside of this create another folder called `layouts`.
216-
3. Create 2 `.handlebars` files: inside layouts create `main.handlebars` and outside of the folder `index.handlebars`
217-
4. The content of `main.handlebars` should be the complete HTML document. Write a basic structure, including a `<head>` and `<body>`. As a final part, inside the `<body>` paste in the following: `{{ body }}` (this injects the HTML from `index.handlebars)` into the body)
218-
5. The content of the `index.handlebars` should be a `<form>`. Make sure it has an `<input>` field, which should be of `type="text"` and have a `name="cityName"`. Also add a submit button. The form should be submitted to our `POST` request endpoint, which is `/weather`. Let the form know about this endpoint by passing it as a value to the `action` property: `action="/weather"`
219-
6. Test out your work! Make sure it renders a form in your browser
215+
2. In the root of the project folder, create a new folder called `views`.
216+
3. Create 1 `.handlebars` file inside the `views` folder, named `index.handlebars`
217+
4. The content of `main.handlebars` should be a regular, complete HTML document. Write a basic structure, including a `<head>` and `<body>`. The latter should include a `<form>`. Make sure it has an `<input>` field, which should be of `type="text"` and have a `name="cityName"`. Also add a submit button. The form should be submitted to our `POST` request endpoint, which is `/weather`. Let the form know about this endpoint by passing it as a value to the `action` property: `action="/weather"`
218+
5. Test out your work! Make sure it renders a form in your browser
220219

221220
### 4.2 The Backend
222221

223222
In this part we'll add another endpoint, with a `POST` method.
224223

225224
1. First let's modify our `/` route. Instead of sending a string, send a template using the `render()` function. Pass in the name of the template, which is `index`
226-
2. To make Express aware of what data type the incoming data is (which is JSON). We do that using the `urlencoded()` method on the express object. Using the `use()` function from `app`, pass in the `urlencoded()` from `express`. Give the `urlencoded()` function the following argument: `{ extended: true }`
225+
2. To make Express aware of what data type the incoming data is (which is JSON). We do that using the `json()` method on the Express object. Using the `use()` function from `app`, pass in the `json()` from `express`.
227226
3. Create a `POST` route, that has as an endpoint: `/weather`
228227
4. Inside the callback function of the route, get access to the `cityName` and put it inside a variable. Hint: use the `body` object from the request to find it.
229228
5. Send the the form input back as a response to the client

week2/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ REST also enables clients to take actions on those resources. We call these acti
3131
The most important features of REST are:
3232

3333
- An application has a `frontend` (client) and a `backend` (server). This is called [separation of concerns](https://medium.com/machine-words/separation-of-concerns-1d735b703a60): each section has its specific job to do. The frontend deals with presenting data in a user friendly way, the backend deals with all the logic and data manipulation
34-
- The server is `stateless`, which means that it doesn't store any data about a client session. Simply put, when you refresh the page you won't keep the data you requested before (unless it's saved in the browser). Whenever a client sends a request to the server, each request from the client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. This makes it possible to handle requests from millions of users.
34+
- The server is `stateless`, which means that it doesn't store any data about a client session. Simply put, when you refresh the page you won't keep the data you requested before (unless it's saved in the browser or in a file on the server). Whenever a client sends a request to the server, each request from the client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. This makes it possible to handle requests from millions of users.
3535
- Server responses can be temporarily stored on the client (a browser) using a process called `caching`: storing files like images or webpages in the browser to load the next time you enter a website (instead of getting them from the server, which generally takes longer to do). Certain user data can also be saved through the browser's `localStorage` or `cookies`
3636
- Client-server communication is done through `Hypertext Transfer Protocol` (more on that later), which serves as the style (the how) of communication.
3737

@@ -120,7 +120,7 @@ For more information check out the following resources:
120120

121121
# 6. Postman
122122

123-
When creating APIs it is important to test if they work as intended. The easiest way to do this is send a request and check the APIs response.
123+
When creating APIs it is important to test if they work as intended. The easiest way to do this is to send a request and check the API's response.
124124

125125
Normally, you would send a request using the browser or the command line. But there's a tool we can use that's made especially for these testing purposes: [Postman](https://www.youtube.com/watch?v=i1jU-kivApg)
126126

@@ -132,9 +132,7 @@ As you can see in the image below, when you enter a request in Postman and click
132132

133133
![postman illustration](https://s3.amazonaws.com/postman-static-getpostman-com/postman-docs/anatomy-of-a-request.png)
134134

135-
Check [this guide](https://learning.getpostman.com/docs/postman/launching_postman/sending_the_first_request/#sending-a-request) to learn how to send a request with Postman.
136-
137-
Alternatively, [watch this video guide](https://www.youtube.com/embed/YKalL1rVDOE?list=PLM-7VG-sgbtBsenu0CM-UF3NZj3hQFs7E).
135+
Watch this [video guide](https://www.youtube.com/embed/YKalL1rVDOE?list=PLM-7VG-sgbtBsenu0CM-UF3NZj3hQFs7E) to learn about how to start sending your first requests with Postman!
138136

139137
## Finished?
140138

week3/LESSONPLAN.md

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,68 @@ FIRST HALF (12:00 - 13:30)
1414

1515
### Middleware
1616

17-
**Explain**
17+
**Explanation**
18+
19+
Middleware is a general term for software that serves to "glue together" separate, often complex and already existing, programs.
20+
21+
In Express, middleware are functions that execute during the lifecycle of a request to the Express server.
22+
23+
Each middleware has access to the HTTP request and response for each route (or path) it’s attached to.
24+
25+
![middleware](https://d33wubrfki0l68.cloudfront.net/a22bb45df146d43b57f2f6c90182d19e7394cd96/d6e10/assets-jekyll/blog/express-middleware-examples/middleware-30b3b30ad54e21d8281719042860f3edd9fb1f40f93150233a08165d908f4631.png)
26+
27+
Additionally, middleware can either terminate the HTTP request or pass it on to another middleware function using the `next()` function (more on that soon). This “chaining” of middleware allows you to compartmentalize your code and create reusable middleware.
28+
29+
**Example**
30+
31+
Try out the following code and use Postman to make the request. Show the student the importance of `express.json()` to parse the request and makes the form data available in the `req.body`.
1832

33+
```js
34+
const express = require('express');
35+
const app = express();
1936

20-
* [Middleware](https://medium.com/@jamischarles/what-is-middleware-a-simple-explanation-bb22d6b41d01)
21-
* [Middleware II](https://www.youtube.com/watch?v=9HOem0amlyg)|
37+
app.use(express.json());
38+
app.post('/test', (req, res) => res.json(req.body));
2239

23-
https://d33wubrfki0l68.cloudfront.net/a22bb45df146d43b57f2f6c90182d19e7394cd96/d6e10/assets-jekyll/blog/express-middleware-examples/middleware-30b3b30ad54e21d8281719042860f3edd9fb1f40f93150233a08165d908f4631.png
40+
const PORT = process.env.PORT || 3000;
41+
app.listen(PORT, () => {
42+
console.log(`Server listening on port ${PORT}`);
43+
});
44+
```
2445

25-
Express middleware are functions that execute during the lifecycle of a request to the Express server. Each middleware has access to the HTTP request and response for each route (or path) it’s attached to. In fact, Express itself is compromised wholly of middleware functions. Additionally, middleware can either terminate the HTTP request or pass it on to another middleware function using next (more on that soon). This “chaining” of middleware allows you to compartmentalize your code and create reusable middleware.
46+
**Exercise**
2647

27-
**Examples**
48+
**Essence**
2849

29-
* express.json() - parses the body of request with type application/json and makes it available as a javascript object
30-
* body-parser - parses the body of request with type form-data and makes it available as javascript object
50+
Middleware allows the web server to modify the request gets in order to make it better interpretable within the route. For example,
3151

3252
### Consuming web APIs
3353

34-
**Explain**
54+
**Explanation**
3555

36-
Traditional server architecture one client one server that does anything:
56+
Traditional server architecture one client one server that does anything:
3757
https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/27f810ea-2722-455a-9a0d-bb5b54c28393/api-based-platforms-api-diagram.png
3858

3959
https://cdn.darknet.org.uk/wp-content/uploads/2018/08/HTTP-Security-Considerations-An-Introduction-To-HTTP-Basics.png
4060

41-
In reality the server does not do everything on its own. Instead it uses services from other servers
61+
In reality the server does not do everything on its own. Instead it uses services from other servers
4262
https://www.notion.so/gajduk/Hosting-b4025782198b494ba6bd053953c8933b#f8f31bc004ab46199639d914daad79fe
4363

4464
Why do we need server-server communication?
45-
* reuse - we do not want to write new code if someone has already done that in the past and we can just use it
46-
* separation-of-concerns - especially in big organizations like netflix etc
4765

48-
**Examples**
66+
- reuse - we do not want to write new code if someone has already done that in the past and we can just use it
67+
- separation-of-concerns - especially in big organizations like netflix etc
4968

50-
* Location services - https://api.postcode.nl/documentation/json-rest/v1/Address/viewByPostcode
51-
* Process payments (Stripe) - https://stripe.com/docs/api/invoices
69+
**Example**
70+
71+
- Location services - https://api.postcode.nl/documentation/json-rest/v1/Address/viewByPostcode
72+
- Process payments (Stripe) - https://stripe.com/docs/api/invoices
5273

5374
**Exercise**
5475

5576
1. Get the image from https://randomfox.ca/floof/ and redirect to it
5677

57-
2. Instead of redirecting show in inside an html
78+
2. Instead of redirecting show it inside HTML
5879

5980
This is prelude to part 2, mention how it is ugly that the HTML and javascript are all mixed up
6081

@@ -80,12 +101,14 @@ How to use them in Node - https://www.npmjs.com/package/handlebars
80101

81102
**Exercise**
82103

83-
- Use handlebars to build a simple UI for reading books from the Library app
84-
- get the books with axios/fetch
85-
- EXTRA: buttons to create, edit, delete book
86-
104+
- Use Handlebars to build a simple UI for reading books from the Library app
105+
- get the books with axios/fetch
106+
- EXTRA: buttons to create, edit, delete book
107+
87108
# !!!IMPORTANT!!!
88109

89-
Ask students to prepare for database course by installing mySQL.
110+
Before class ends, ask the students to prepare for the next module ([Databases](http://github.com/hackyourfuture/databases)) course by installing MySQL:
90111

91-
112+
- On Windows: download this [MySQL Community Server](https://dev.mysql.com/downloads/mysql/)
113+
- On Linux: download this [MySQL Community Server](https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-server_8.0.19-1ubuntu19.10_amd64.deb-bundle.tar)
114+
- On MacOS: download this [MySQL Community Server](https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.19-macos10.15-x86_64.dmg)

0 commit comments

Comments
 (0)