the middle tier with hapi
Background & Context
- building new applications on existing services
- embed "/api" routes in FE node.js apps
- shared module(s)
dedicated middle tier
- giving a problem the attention it deserves
- hapi offers a lot for this suite of problems
- separation of responsibilities proved beneficial
UI can focus on UI
- UI often iterates faster than service communication
- Testing UI apps became simpler
- Simpler for new team members to grok
isolating service interaction
- separating responsibilities lets each layer focus on a more specific set of problems
- smaller problems often equal simpler solutions
- one place to manage service dependencies
logging
- became more targeted/focused
- track events/errors across apps & middle tier w/ request.id generated by hapi
- ops logging is helpful to gain easy/quick insight into memory/cpu usage
- pluggable - easy to write your own reporters
testing
- apis are often very targeted i/o verification
- made easy w/ hapi & lab
- server.inject() makes it easy to simulate requests
- mock 3rd party calls, i.e. http requests
- lab offers built-in code-coverage support
input validation with joi
- existing services often don't enforce what you want to enforce
- consistent enforcement of data contracts & responses
- simpler app code w/o need to check type/existence/values
hapi & friends are highly modular
- largely focused on building modules that work well together, but also independently.
- Joi plugs into express easily
- Lab will be familiar to anyone who's used mocha
- easy to enforce code coverage w/o another tool
- Hapi is opinionated about your http server layer, but largely hands-off w/ regards to how you architect & abstract your business logic
- we were able to re-use a lot of pre-existing approaches & modules
- less worry of lock-in
Middle Tier w/ hapi.js
By Brad Harris
Middle Tier w/ hapi.js
- 1,514