Sample Courses

Let's add some sample courses to our application:

public class ApiServer {
  public static void main(String[] args) {
+   List<Course> courses = new ArrayList<>();
+   courses.add(new Course("EN.500.112","GATEWAY COMPUTING: JAVA"));
+   courses.add(new Course("EN.601.220","INTERMEDIATE PROGRAMMING"));
+   courses.add(new Course("EN.601.226","DATA STRUCTURES"));
+   courses.add(new Course("EN.601.229","COMPUTER SYSTEM FUNDAMENTALS"));
+   courses.add(new Course("EN.601.231","AUTOMATA and COMPUTATION THEORY"));
    
-   get("/api/courses", (req, res) -> "List of current CS courses!");
+   get("/api/courses",  (req, res) -> courses);
  }
}

Stop the server and run it again. Then, go to Postman and send a Get request to http://localhost:4567/api/courses to get the list of sample courses:

Notice the format and content of data received by Postman matches the output of System.out.println(courses) if we were to print out the courses to the terminal.