npm install
to verify all dependencies are properly installed.npm run start
to start.
- Open a browser and access
localhost:1338
An incoming request follows the order :
- Request - Received from the browser.
- Routes - Determines which handler to use.
- Handler - Calls specific services to retrieve data.
- Services - Retrieves the data.
- Handler - Returns the data or calls a transform to manipulate it.
- Transform (optional) - Manipulate the data.
- Handler (optional) - Returns the data.
- Response - Send the data back to the browser.
Below are the different parts of the flow described with what they do.
- Parse the request from the browser and determine which handler(s) to call.
- Are separated by HTTP
method
s,path
urls, andconfig
handler values/functions. - Are all maintained within a single file
routes.js
. - Additional information on Hapi routes can be found here.
- Handle the requests from the user.
- Orchestrate most of the business logic on the data.
- Use
Joi
for validation. - Calls services to retrieve data.
- Calls transforms to manipulate data.
- Can be accessed through the Swagger browser tool.
This framework encourages good documentation within the code by including the following in the export statement:
- handler
- description
- notes
- tags
- validate
This information will be used in the Swagger browser tool to help with the development/debugging process. This tool is located at localhost:1338
- Retrieve data to send back to the Handler.
- Interact directly with the database(s).
- May not be native to the project.
- Do little business logic if at all.
- Manipulate the data before sending it back to the user.
- Are not required for every Handler.
- Can be selective of return data with
Destructuring
.
Destructuring
is an es6 implementation that helps build new structures from previous structure's data. A tutorial on destructuring can be found here.
- Provide little bits of often repeated code. e.g. verifying database connections.
- Are often called by services and some handlers.