outmoded / university

Community learning experiment
Other
371 stars 194 forks source link

write assignment10 prerequisites #256

Closed zoe-1 closed 6 years ago

zoe-1 commented 7 years ago

Assignment code located: relevant documentation test/api/user.js lib/api/prerequisites lib/api/user.js

zoe-1 commented 7 years ago

Assignment10 - prerequisites

After completing assignment9, we have a general understanding of the request lifecycle and how to extend it. In this assignment, we will build on that knowledge and extend the request lifecycle for the /login route using prerequisites. The objective will be to tidy up the /login route handler.

Assigment9's /login route handler in ./lib/api/user.js contains all authentication and session generation logic. This makes the handler a bit cluttered. To clean things up, we move the authentication and session generation logic out of handler into two prerequisite functions: getUser() & createSession(). See prerequisite functions here.

Prerequisite functions are executed right before the handler in the request lifecycle. We will use prerequisites to move complex logic from the handler to the prerequisite functions. Assignment requirements below:

At completion of assignment10 when we read our /login route we see:

It is an extremely readable route object. One look gives a nice overview of everything going on in the route. The conciseness and readability show off the beauty of the hapi request lifecycle design pattern. And, the elegance motivates us to use hapi to write clean and maintainable code.

Review:

Take sometime and look over the request lifecycle document. Then, find each element in the /login route object which relates to the request lifecycle for this route. Locate where in the lifecycle each element will be executed. The goal is to understand how the route object can be configured to execute methods at different stages in the lifecycle.

focus on: