-
Notifications
You must be signed in to change notification settings - Fork 9
[Foundation] session plan intro to backend #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
999008b
feat: create a sample webserver scaffolding in session materials
magdazelena e052777
chore: add simple operation and query example
magdazelena 634a53d
chore: add sample sqlite connection
magdazelena 32d7950
feat: added Postman collection and updates readme
magdazelena d4f8163
feat: add the lesson flow to the session plan readme
magdazelena 17d8069
chore: fix lint
magdazelena 5fbaebf
chore: fix lint
magdazelena e8c4c64
chore: rename collection file and run prettier
magdazelena 397f238
chore: added timings and formatting and missing links
magdazelena 8d6a665
chore: add Postman basics timeframe
magdazelena 6f78ce5
chore: add link to the assignment repo
magdazelena 657e85f
chore: remove promises, add knex
magdazelena 51116b9
chore: add knex to readme
magdazelena e776e6c
chore: add CRUD reference
magdazelena 8d7b2e3
chore: more descriptive link
magdazelena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
courses/foundation/intro-to-backend/week1/session-materials/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Session materials | ||
|
|
||
| ## Contents | ||
|
|
||
| 1. `index.js` file is a playground for live coding during the session. It is deliberately empty. | ||
| 2. `/examples` folder contains code inspirations to demonstrate during session to showcase possibilies. | ||
| - `pages.js` show how simple HTML can be passed via endpoints | ||
| - `math.js` show that endpoints can get passed variables and perform operations | ||
| - `data.js` show how to get access to the data from a database | ||
| 3. Postman collection JSON | ||
|
|
||
| --- | ||
|
|
||
| ## Node JS | ||
|
|
||
| ### Getting started | ||
|
|
||
| 1. Navigate to directory in your console | ||
| 2. Run `npm i` | ||
| 3. Run `npm run start` | ||
|
|
||
| #### Tip | ||
|
|
||
| If you prefer, you might run examples directly, using: | ||
|
|
||
| ```bash | ||
| node --watch examples/[YOUR CHOSEN EXAMPLE].js | ||
| ``` | ||
|
|
||
| ## Postman | ||
|
|
||
| 1. Open Postman app | ||
| 2. Click on `Import` button next to your user name | ||
| 3. Import the collection from the repo | ||
| 4. Make sure your Node server is running to access needed endpoints |
43 changes: 43 additions & 0 deletions
43
courses/foundation/intro-to-backend/week1/session-materials/examples/data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import express from "express"; | ||
| import knexLibrary from "knex"; | ||
|
|
||
| const dbFile = "../../../databases/week1/assets/test.sqlite3"; | ||
| // NOTE: if you didn't clone the entire programme repo | ||
| // replace the above path with actual path to your sqlite instance | ||
|
|
||
| const knex = knexLibrary({ | ||
| client: "sqlite3", | ||
| connection: { | ||
| filename: dbFile, | ||
| }, | ||
| }); | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(express.json()); | ||
|
|
||
| app.get("/", async (request, response) => { | ||
| const { query } = request; | ||
|
|
||
| if (query.table) { | ||
| // for example: http://localhost:3000/?table=task | ||
| const data = await knex.raw(`select * from ${query.table}`); | ||
| return response.json(data); | ||
| } | ||
|
|
||
| const tables = await knex.raw(`SELECT name FROM sqlite_schema`); | ||
| response.json(tables); | ||
| }); | ||
|
|
||
| app.post("/status", async (request, response) => { | ||
| const { id, name } = request.body; | ||
|
|
||
| if (!id || !name || name.length === 0) return response.sendStatus(400); | ||
|
|
||
| await knex.raw(`insert into status(id, name) values(${id}, "${name}")`); | ||
| response.sendStatus(200); | ||
| }); | ||
|
|
||
| app.listen(3000, function () { | ||
| console.log(`> Ready on http://localhost:3000`); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
courses/foundation/intro-to-backend/week1/session-materials/examples/math.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import express from "express"; | ||
| const app = express(); | ||
|
|
||
| app.get("/", (_request, response) => { | ||
| response.send("Let's do some math!"); | ||
| }); | ||
|
|
||
| app.get("/add", (request, response) => { | ||
| console.log("Your query: " + request.query); | ||
|
|
||
| if (!request.query.a && !request.query.b) | ||
| return response.send(` | ||
| <h1> No values to add! </h1> | ||
| Append <code>?a=2&b=3</code> to the url | ||
| `); | ||
|
|
||
| const { a, b } = request.query; | ||
| const sum = Number(a) + Number(b); | ||
|
|
||
| response.send(sum); | ||
| }); | ||
|
|
||
| app.listen(3000, function () { | ||
| console.log(`> Ready on http://localhost:3000`); | ||
| }); |
38 changes: 38 additions & 0 deletions
38
courses/foundation/intro-to-backend/week1/session-materials/examples/pages.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import express from "express"; | ||
| const app = express(); | ||
|
|
||
| app.get("/", (_request, response) => { | ||
| response.send(` | ||
| <body> | ||
| <h1>Main page</h1> | ||
| <h2>Shows main content</h2> | ||
| </body> | ||
| `); | ||
| }); | ||
|
|
||
| app.get("/about", (_request, response) => { | ||
| response.send(` | ||
| <body> | ||
| <h1>About</h1> | ||
| <p>This is an about page</p> | ||
| </body> | ||
| `); | ||
| }); | ||
|
|
||
| app.get("/contact", (_request, response) => { | ||
| response.send(` | ||
| <body> | ||
| <h1>Contact</h1> | ||
| <p>This is a contact page</p> | ||
| <form> | ||
| <label>name</label> | ||
| <input placeholder="Write your name"> | ||
| <button>Contact me</button> | ||
| </form> | ||
| </body> | ||
| `); | ||
| }); | ||
|
|
||
| app.listen(3000, function () { | ||
| console.log(`> Ready on http://localhost:3000`); | ||
| }); |
10 changes: 10 additions & 0 deletions
10
courses/foundation/intro-to-backend/week1/session-materials/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import express from "express"; | ||
| const app = express(); | ||
|
|
||
| app.get("/", (_request, response) => { | ||
| response.send("hello"); | ||
| }); | ||
|
|
||
| app.listen(3000, function () { | ||
| console.log(`> Ready on http://localhost:3000`); | ||
| }); |
114 changes: 114 additions & 0 deletions
114
...ndation/intro-to-backend/week1/session-materials/intro-to-backend.postman_collection.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| { | ||
| "info": { | ||
| "_postman_id": "f1c288ff-7ed3-482a-9c8e-a6dd5a99421d", | ||
| "name": "Intro to backend", | ||
| "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
| "_exporter_id": "48182721", | ||
| "_collection_link": "https://magdazelena-ea3683e1-7432080.postman.co/workspace/Magdalena-Odrow%C4%85%C5%BC-%C5%BBelezik's-Wor~d3429c08-9437-4576-84c6-94f688cd37c5/collection/48182721-f1c288ff-7ed3-482a-9c8e-a6dd5a99421d?action=share&source=collection_link&creator=48182721" | ||
| }, | ||
| "item": [ | ||
| { | ||
| "name": "sample requests", | ||
| "item": [ | ||
| { | ||
| "name": "sample get", | ||
| "request": { | ||
| "method": "GET", | ||
| "header": [], | ||
| "url": { | ||
| "raw": "{{url}}/", | ||
| "host": ["{{url}}"], | ||
| "path": [""] | ||
| } | ||
| }, | ||
| "response": [] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name": "database endpoints", | ||
| "item": [ | ||
| { | ||
| "name": "get all tables", | ||
| "request": { | ||
| "method": "GET", | ||
| "header": [], | ||
| "url": { | ||
| "raw": "{{url}}/", | ||
| "host": ["{{url}}"], | ||
| "path": [""] | ||
| } | ||
| }, | ||
| "response": [] | ||
| }, | ||
| { | ||
| "name": "get data by table", | ||
| "request": { | ||
| "method": "GET", | ||
| "header": [], | ||
| "url": { | ||
| "raw": "{{url}}/?table=status", | ||
| "host": ["{{url}}"], | ||
| "path": [""], | ||
| "query": [ | ||
| { | ||
| "key": "table", | ||
| "value": "status" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "response": [] | ||
| }, | ||
| { | ||
| "name": "add status", | ||
| "request": { | ||
| "method": "POST", | ||
| "header": [], | ||
| "body": { | ||
| "mode": "raw", | ||
| "raw": "{\r\n \"name\": \"In progress\",\r\n \"id\": 4\r\n}", | ||
| "options": { | ||
| "raw": { | ||
| "language": "json" | ||
| } | ||
| } | ||
| }, | ||
| "url": { | ||
| "raw": "{{url}}/status", | ||
| "host": ["{{url}}"], | ||
| "path": ["status"] | ||
| } | ||
| }, | ||
| "response": [] | ||
| } | ||
| ], | ||
| "description": "Make sure your server is running.\n\nMake sure you have correct endpoints in index.js\n\nOtherwise make sure you ran: \n`node --watch examples/data.js`" | ||
| } | ||
| ], | ||
| "event": [ | ||
| { | ||
| "listen": "prerequest", | ||
| "script": { | ||
| "type": "text/javascript", | ||
| "packages": {}, | ||
| "exec": [""] | ||
| } | ||
| }, | ||
| { | ||
| "listen": "test", | ||
| "script": { | ||
| "type": "text/javascript", | ||
| "packages": {}, | ||
| "exec": [""] | ||
| } | ||
| } | ||
| ], | ||
| "variable": [ | ||
| { | ||
| "key": "url", | ||
| "value": "http://localhost:3000", | ||
| "type": "string" | ||
| } | ||
| ] | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩