Skip to content

Instantly share code, notes, and snippets.

@pwrmvspark
Forked from Shurlow/rest-express.md
Last active June 17, 2019 19:04
Show Gist options
  • Select an option

  • Save pwrmvspark/9a30a62870d314f3f9334372d78a50c5 to your computer and use it in GitHub Desktop.

Select an option

Save pwrmvspark/9a30a62870d314f3f9334372d78a50c5 to your computer and use it in GitHub Desktop.

Revisions

  1. pwrmvspark revised this gist Jun 17, 2019. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions rest-express.md
    Original 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
    - Get one author
    - Add new author
    - Get all books by author
    - Get one book by author
    - 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?
    - **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')
    res.sendFile('./public/index.html') //sets status code here
    })

    app.listen(3000)
  2. pwrmvspark revised this gist Jun 17, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rest-express.md
    Original 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
    ## REST - //representational state transfer

    * 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?

  3. @Shurlow Shurlow revised this gist Jun 17, 2019. 1 changed file with 20 additions and 7 deletions.
    27 changes: 20 additions & 7 deletions rest-express.md
    Original file line number Diff line number Diff line change
    @@ -67,7 +67,7 @@
    ## Express

    * Given the following examples of a web server written with Node http and Express that perform the same tasks
    * Compare the two example HTTP web servers bellow:

    ```javascript
    const fs = require('fs')
    @@ -92,13 +92,11 @@
    response.end(data)
    })
    }
    }) // and much more besides
    })
    ```

    ```javascript
    const express = require('express')
    const http = require('http')

    const app = express()

    app.use(express.static('./public'))
    @@ -107,9 +105,24 @@
    res.sendFile('./public/index.html')
    })

    http.createServer(app).listen(3000)
    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
    * 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
  4. @Shurlow Shurlow revised this gist Jun 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rest-express.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # REST (Representational State Transfer) & Express
    # REST & Express

    ### Objectives

  5. @Shurlow Shurlow revised this gist Jun 17, 2019. 1 changed file with 34 additions and 40 deletions.
    74 changes: 34 additions & 40 deletions rest-express.md
    Original 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:** How would you represent the API route to get a limited number of authors?
    - **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')
    ```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'})
    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)
    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' })
    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)
    fs.readFile(__dirname + '/public/index.html', function(err, data) {
    if(err) console.log(err)

    response.end(data)
    })
    }
    }) // and much more besides
    ```
    response.end(data)
    })
    }
    }) // and much more besides
    ```

    ```javascript
    const express = require('express')
    const http = require('http')
    ```javascript
    const express = require('express')
    const http = require('http')

    const app = express()
    const app = express()

    app.use(express.static('./public'))
    app.use(express.static('./public'))

    app.get('/', function(req, res, next) {
    res.sendFile('./public/index.html')
    })
    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')
    ```
    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.

    https://github.com/Shurlow/rest-express-lesson
    * What parts are of the process does Express help you with
  6. @Shurlow Shurlow revised this gist Jun 17, 2019. 1 changed file with 11 additions and 10 deletions.
    21 changes: 11 additions & 10 deletions rest-express.md
    Original 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?
    - 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 = [
    @@ -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
    ## Express

    * Given the following examples of a web server written with Node http and Express that perform the same tasks

  7. @Shurlow Shurlow renamed this gist Jun 17, 2019. 1 changed file with 53 additions and 4 deletions.
    57 changes: 53 additions & 4 deletions rest.md → rest-express.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    # REST (Representational State Transfer)
    # REST (Representational State Transfer) & Express

    ### 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
    - [ ] Explain what express is and why it's useful
    - [ ] Build RESTful routes using express

    ## Guiding Questions
    ## REST

    * What is a resource?

    @@ -64,7 +65,55 @@

    > Your answer...
    ## Practice
    ## 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.

  8. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion rest.md
    Original 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? The
    * 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 = [
  9. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rest.md
    Original 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 conventions for various routes including naming convention, HTTP verbs, and status codes
    - [ ] Identify RESTful conventions for API routes
    - [ ] Build RESTful routes for a given resource

    ## Guiding Questions
  10. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rest.md
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,6 @@
    ## Practice

    Fork & clone this simple express server and complete the descirbed RESTful routes.
    Fork & clone this express server app and complete the descirbed RESTful routes in app.js.

    https://github.com/Shurlow/rest-express-lesson
  11. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion rest.md
    Original 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
    Fork & clone this simple express server and complete the descirbed RESTful routes.

    https://github.com/Shurlow/rest-express-lesson
  12. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion rest.md
    Original 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
  13. @Shurlow Shurlow revised this gist Nov 2, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions rest.md
    Original 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
  14. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions rest.md
    Original 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...
    https://learn.co/lessons/rest-quiz
  15. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions rest.md
    Original 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?

    | Action | Method | Path | Body |
    |---|---|---|---|
    | _ | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |

    > 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
  16. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions rest.md
    Original 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 @@
    ]
    ```

    > Your answer...
    **Challenge:** How would you represent the API route to get a limited number of authors?

    * Build RESTful routes for one of the following resources: cards, dogs, engineers

    > Your answer...
    https://learn.co/lessons/rest-quiz
  17. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rest.md
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,8 @@

    | Action | Method | Path | Body |
    |---|---|---|---|
    | ... | | | |
    | ... | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |
  18. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions rest.md
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,11 @@

    | Action | Method | Path | Body |
    |---|---|---|---|
    | | | | |
    | | | | |
    | | | | |
    | ... | | | |
    | ... | | | |
    | _ | | | |
    | _ | | | |
    | _ | | | |

    > Your answer...
  19. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions rest.md
    Original 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
  20. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions rest.md
    Original 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?
    * How would you build RESTful routes for the following data? The

    ```js
    const sandwiches = [
    const authors = [
    {
    name: 'Sausy Sausage'
    ingredients: ['sausage', 'tangy sauce']
    name: 'Haruki Murakami',
    books: [
    { title: 'Hard-Boiled Wonderland and the End of the World' },
    { title: 'The Wind-Up Bird Chronicle' }
    ]
    },
    {
    name: 'The Godfather'
    ingredients: ['mozarella', 'tomato']
    name: 'Kurt Vonnegut'
    books: [
    { title: 'Slaughterhouse-Five' }
    ]
    }
    ]
    ```
  21. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions rest.md
    Original 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

  22. @Shurlow Shurlow revised this gist Nov 1, 2018. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions rest.md
    Original 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...
    > Your answer...
  23. @Shurlow Shurlow created this gist Nov 1, 2018.
    21 changes: 21 additions & 0 deletions rest.md
    Original 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...