1 of 5

EXPRESS ROUTES

2 of 5

Welcome!

3 of 5

Cycle-1 : Create Student routes

  • Create a folder ‘route’
    • lets create ‘student.js’ file

  • Lets create student model:
    • let student= [{id:1, name: ‘Dan’}, {id:2, name: ‘Karen’ }, …add some more]

  • Time to create the following routes:
    • get ‘/’
    • get ‘/:id’
    • post ‘/’
    • put ‘/:id’
    • delete ‘/:id’

  • Lets not forget error handling and require ‘student.js’ in our ‘app.js’
  • Review at 11:30am

4 of 5

Cycle – 2: Create Test routes

  • Starting point: git checkout cycle-2
  • In your ‘route’ folder:
    • lets create ‘test.js’ file

  • Lets create test model:
    • let test= [{id : 1, subject : 'English', score : 78, studentId : 1}, …add some more]

  • Time to create the following routes:
    • get ‘/’
    • get ‘/:id’
    • post ‘/’
    • put ‘/:id’
    • delete ‘/:id’

  • Lets not forget to require ‘test.js’ in our ‘app.js ‘
  • Review at 1:00pm

5 of 5

Cycle – 3 : Time to refactor

  • Starting point: git checkout cycle-3
  • Lets add 2 more routes to test.js
    • Get top scoring student. get ‘/top’
    • Get mean score for student. get ‘/:id/mean’
    • It is important to know where which route hits first

  • Create ’db’ folder and lets add our models in ‘db.js:
    • Don’t forget to export the models and import them in your routes.

  • Review at 3:15pm