-
-
Save pwrmvspark/9a30a62870d314f3f9334372d78a50c5 to your computer and use it in GitHub Desktop.
Revisions
-
pwrmvspark revised this gist
Jun 17, 2019 . 1 changed file with 13 additions and 12 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,12 @@ | Action | Method | Path | Body | |---|---|---|---| | _ | | | | get one - GET - /cars/<VIN> - number //12345 | _ | | | | get all - GET - /cars?model=honda - [12345, 23456, 34567] ?limit=10 | _ | | | | create - POST - /cars - "VIN" | _ | | | | update - PUT - /cars/<VIN> | _ | | | | delete - DELETE - /cars/<VIN> > Your answer... @@ -53,15 +54,15 @@ ] ``` - Get all authors - /authors - Get one author - /authors/name - Add new author - POST /authors {} - Get all books by author - GET /authors/name/books - Get one book by author - - Add new book by author - Edit one book by author - Delete one book by author - **Challenge:** Get a specific number of authors? GET /authors?limit=10&start=5 > Your answer... @@ -102,7 +103,7 @@ app.use(express.static('./public')) app.get('/', function(req, res, next) { res.sendFile('./public/index.html') //sets status code here }) app.listen(3000) -
pwrmvspark revised this gist
Jun 17, 2019 . 1 changed file with 2 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,11 @@ - [ ] Explain what express is and why it's useful - [ ] Build RESTful routes using express ## REST - //representational state transfer * What is a resource? > * What are the five common actions of an API? What methods and status codes are typically used for the five common actions? -
Shurlow revised this gist
Jun 17, 2019 . 1 changed file with 20 additions and 7 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -67,7 +67,7 @@ ## Express * Compare the two example HTTP web servers bellow: ```javascript const fs = require('fs') @@ -92,13 +92,11 @@ response.end(data) }) } }) ``` ```javascript const express = require('express') const app = express() app.use(express.static('./public')) @@ -107,9 +105,24 @@ res.sendFile('./public/index.html') }) app.listen(3000) console.log('Express server is listening on port 3000') ``` * What tasks does this server perform? * What parts of the process does Express help you with? ## Practice Lets practice building a simple server with express. - Create a new folder called `express-lesson` - Run `npm init -y` - Install express dependencies: `npm i express body-parser nodemon morgan` - Create a file called `app.js` - Add the following script to `package.json`: `"start": "nodemon app.js"` - Build the basic express server and open connections on port 3000. - Copy the author data from above into `app.js` - Implement the following author routes in express: - Get All - Post - Get One -
Shurlow revised this gist
Jun 17, 2019 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # REST & Express ### Objectives -
Shurlow revised this gist
Jun 17, 2019 . 1 changed file with 34 additions and 40 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -61,61 +61,55 @@ - Add new book by author - Edit one book by author - Delete one book by author - **Challenge:** Get a specific number of authors? > Your answer... ## Express * Given the following examples of a web server written with Node http and Express that perform the same tasks ```javascript const fs = require('fs') const http = require('http') const server = http.createServer(function(request, response) { if(request.url === '/logo.png') { response.writeHead(200, {'Content-Type': 'image/gif'}) fs.readFile(__dirname + '/public/logo.png', function(err, data) { if(err) console.log(err) response.end(data) }) } else if (request.url === '/'){ response.writeHead(200, {'Content-Type': 'text/html' }) fs.readFile(__dirname + '/public/index.html', function(err, data) { if(err) console.log(err) response.end(data) }) } }) // and much more besides ``` ```javascript const express = require('express') const http = require('http') const app = express() app.use(express.static('./public')) app.get('/', function(req, res, next) { res.sendFile('./public/index.html') }) http.createServer(app).listen(3000) console.log('Express server is listening on port 3000') ``` * What are the tasks performed? * What parts are of the process does Express help you with -
Shurlow revised this gist
Jun 17, 2019 . 1 changed file with 11 additions and 10 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -34,14 +34,6 @@ > https://learn.co/lessons/rest-quiz * How would you build RESTful routes for the following data? ```js const authors = [ @@ -60,12 +52,21 @@ } ] ``` - Get all authors - Get one author - Add new author - Get all books by author - Get one book by author - Add new book by author - Edit one book by author - Delete one book by author **Challenge:** How would you represent the API route to get a limited number of authors? > Your answer... ## Express * Given the following examples of a web server written with Node http and Express that perform the same tasks -
Shurlow renamed this gist
Jun 17, 2019 . 1 changed file with 53 additions and 4 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ # REST (Representational State Transfer) & Express ### Objectives - [ ] Describe the concept of resources in relation to REST and APIs - [ ] Identify RESTful conventions for API routes - [ ] Explain what express is and why it's useful - [ ] Build RESTful routes using express ## REST * What is a resource? @@ -64,7 +65,55 @@ > Your answer... ## Express * Given the following examples of a web server written with Node http and Express that perform the same tasks ```javascript const fs = require('fs') const http = require('http') const server = http.createServer(function(request, response) { if(request.url === '/logo.png') { response.writeHead(200, {'Content-Type': 'image/gif'}) fs.readFile(__dirname + '/public/logo.png', function(err, data) { if(err) console.log(err) response.end(data) }) } else if (request.url === '/'){ response.writeHead(200, {'Content-Type': 'text/html' }) fs.readFile(__dirname + '/public/index.html', function(err, data) { if(err) console.log(err) response.end(data) }) } }) // and much more besides ``` ```javascript const express = require('express') const http = require('http') const app = express() app.use(express.static('./public')) app.get('/', function(req, res, next) { res.sendFile('./public/index.html') }) http.createServer(app).listen(3000) console.log('Express server is listening on port 3000') ``` * What are the tasks performed? * What parts are of the process does Express help you with Fork & clone this express server app and complete the descirbed RESTful routes in app.js. -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 9 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,15 @@ > https://learn.co/lessons/rest-quiz * How would you build RESTful routes for the following data? - Get all authors - Get one author - Add new author - Get all books by author - Get one book by author - Add new book by author - Edit one book by author - Delete one book by author ```js const authors = [ -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ ### Objectives - [ ] Describe the concept of resources in relation to REST and APIs - [ ] Identify RESTful conventions for API routes - [ ] Build RESTful routes for a given resource ## Guiding Questions -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -58,6 +58,6 @@ ## Practice Fork & clone this express server app and complete the descirbed RESTful routes in app.js. https://github.com/Shurlow/rest-express-lesson -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 3 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -58,4 +58,6 @@ ## Practice Fork & clone this simple express server and complete the descirbed RESTful routes. https://github.com/Shurlow/rest-express-lesson -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 4 additions and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -55,4 +55,7 @@ **Challenge:** How would you represent the API route to get a limited number of authors? > Your answer... ## Practice Fork & clone this simple express server and complete the descirbed RESTful routes: https://github.com/Shurlow/rest-express-lesson -
Shurlow revised this gist
Nov 2, 2018 . 1 changed file with 4 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,10 @@ > Your answer... * Attept this REST Quiz! > https://learn.co/lessons/rest-quiz * How would you build RESTful routes for the following data? The ```js -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 0 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,4 @@ **Challenge:** How would you represent the API route to get a limited number of authors? > Your answer... -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 8 additions and 8 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -14,18 +14,18 @@ * What are the five common actions of an API? What methods and status codes are typically used for the five common actions? > Your answer... * Build RESTful routes for one of the following resources: cards, dogs, engineers | Action | Method | Path | Body | |---|---|---|---| | _ | | | | | _ | | | | | _ | | | | | _ | | | | | _ | | | | > Your answer... * How would you build RESTful routes for the following data? The -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 5 additions and 3 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,10 @@ > Your answer... * Build RESTful routes for one of the following resources: cards, dogs, engineers > Your answer... * How would you build RESTful routes for the following data? The ```js @@ -44,10 +48,8 @@ ] ``` **Challenge:** How would you represent the API route to get a limited number of authors? > Your answer... https://learn.co/lessons/rest-quiz -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 2 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,8 @@ | Action | Method | Path | Body | |---|---|---|---| | _ | | | | | _ | | | | | _ | | | | | _ | | | | | _ | | | | -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 5 additions and 3 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,11 @@ | Action | Method | Path | Body | |---|---|---|---| | ... | | | | | ... | | | | | _ | | | | | _ | | | | | _ | | | | > Your answer... -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 6 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,12 @@ * What are the five common actions of an API? What methods and status codes are typically used for the five common actions? | Action | Method | Path | Body | |---|---|---|---| | | | | | | | | | | | | | | | > Your answer... * How would you build RESTful routes for the following data? The -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 11 additions and 6 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -16,17 +16,22 @@ > Your answer... * How would you build RESTful routes for the following data? The ```js const authors = [ { name: 'Haruki Murakami', books: [ { title: 'Hard-Boiled Wonderland and the End of the World' }, { title: 'The Wind-Up Bird Chronicle' } ] }, { name: 'Kurt Vonnegut' books: [ { title: 'Slaughterhouse-Five' } ] } ] ``` -
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 2 additions and 0 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -36,4 +36,6 @@ * Build RESTful routes for one of the following resources: cards, dogs, engineers > Your answer... https://learn.co/lessons/rest-quiz
-
Shurlow revised this gist
Nov 1, 2018 . 1 changed file with 20 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,25 @@ * What are the five common actions of an API? What methods and status codes are typically used for the five common actions? > Your answer... * How would you build RESTful routes for the following data? ```js const sandwiches = [ { name: 'Sausy Sausage' ingredients: ['sausage', 'tangy sauce'] }, { name: 'The Godfather' ingredients: ['mozarella', 'tomato'] } ] ``` > Your answer... * Build RESTful routes for one of the following resources: cards, dogs, engineers > Your answer... -
Shurlow created this gist
Nov 1, 2018 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # REST (Representational State Transfer) ### Objectives - [ ] Describe the concept of resources in relation to REST and APIs - [ ] Identify conventions for various routes including naming convention, HTTP verbs, and status codes - [ ] Build RESTful routes for a given resource ## Guiding Questions * What is a resource? > Your answer... * What are the five common actions of an API? What methods and status codes are typically used for the five common actions? > Your answer... * Build RESTful routes for one of the following resources: cards, dogs, engineers > Your answer...