labs / tiddlers / content / labs / lab07 / _Labs_07_The Student

We don't want to add all of our API routes (that is what these lambda expressions are called in Jooby) to the Server class (since we will end up with quite a few before we are finished). We should create a student module that defines the web service API for managing student domain data. This also allows us to easily turn the student module into its own microservice since we can create a server class that only loads this module.

  1. Create a new class in the web package named StudentModule. Make it extend Jooby.

  2. Add a default constructor.

  3. Move the two routes from the server constructor into the constructor of the new class. You should remove the original versions of the routes from the Server class.

    Leave the setServerOptions call and DAO field where they.

  4. DAO injection time. Modify the constructor in the new class so that it takes the DAO as a parameter. Remember to use the interface type.

    The server class will create the DAOs and pass them into the modules.

  5. Back in the server class add the following to the constructor:

      mount(new StudentModule(dao));

    The mount method will add all of the routes that were declared in the StudentModule to the service.

  6. Restart and test that the server still works correctly.