You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: week2/MAKEME.md
+7-8Lines changed: 7 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -205,25 +205,24 @@ This week's homework we will expand on that, in 2 parts:
205
205
206
206
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!
207
207
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)):
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
220
219
221
220
### 4.2 The Backend
222
221
223
222
In this part we'll add another endpoint, with a `POST` method.
224
223
225
224
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`.
227
226
3. Create a `POST` route, that has as an endpoint: `/weather`
228
227
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.
229
228
5. Send the the form input back as a response to the client
Copy file name to clipboardExpand all lines: week2/README.md
+3-5Lines changed: 3 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ REST also enables clients to take actions on those resources. We call these acti
31
31
The most important features of REST are:
32
32
33
33
- 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.
35
35
- 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`
36
36
- Client-server communication is done through `Hypertext Transfer Protocol` (more on that later), which serves as the style (the how) of communication.
37
37
@@ -120,7 +120,7 @@ For more information check out the following resources:
120
120
121
121
# 6. Postman
122
122
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.
124
124
125
125
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)
126
126
@@ -132,9 +132,7 @@ As you can see in the image below, when you enter a request in Postman and click
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!
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`.
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**
26
47
27
-
**Examples**
48
+
**Essence**
28
49
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,
31
51
32
52
### Consuming web APIs
33
53
34
-
**Explain**
54
+
**Explanation**
35
55
36
-
Traditional server architecture one client one server that does anything:
56
+
Traditional server architecture one client one server that does anything:
- Process payments (Stripe) - https://stripe.com/docs/api/invoices
52
73
53
74
**Exercise**
54
75
55
76
1. Get the image from https://randomfox.ca/floof/ and redirect to it
56
77
57
-
2. Instead of redirecting show in inside an html
78
+
2. Instead of redirecting show it inside HTML
58
79
59
80
This is prelude to part 2, mention how it is ugly that the HTML and javascript are all mixed up
60
81
@@ -80,12 +101,14 @@ How to use them in Node - https://www.npmjs.com/package/handlebars
80
101
81
102
**Exercise**
82
103
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
+
87
108
# !!!IMPORTANT!!!
88
109
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:
90
111
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