- Create a route
- Map a route to a controller/action
- Send JSON data as a response
We'll continue building our API for viewing student data. In this lesson, we'll add some routes and controller logic for displaying data about our students.
To get set up, run:
$ bundle install
$ rails db:migrate db:seedThis will download all the dependencies for our app and set up the database.
- Create a route for making a
GETrequest to/students - Generate a
StudentsControllerwith anindexaction for handling the route; don't forget to pass the--no test frameworkargument! - In the
indexaction, return JSON data representing a list of all students
- Create a route for making a
GETrequest to/students/grades - Add a
gradesaction in theStudentsControllerfor handling that route - In the
gradesaction, return JSON data representing a list of all students, ordered by grade from highest to lowest
Un-comment out the last test in /spec/requests/students_spec.rb to complete the bonus.
- Create a route for making a
GETrequest to/students/highest-grade - Add a
highest_gradeaction in theStudentsControllerfor handling that route - In the
highest_gradeaction, return JSON data representing the one student with the highest grade - Note: while the other two routes should return an array of data, this route should return just one student object!