Code Robust APIs with the Hapi.js Server Framework for Node.js
Table of Contents
Course IntroductionRyan Chenkie introduces the course on Hapi.js, a web application server framework for Node.js, and reviewing the course agenda that includes making an API.
Hapi.js IntroductionRyan reviews the history of Hapi.js and its features that includes: error objects, validation, sessions, CORS, and logging. Then reviews Hapi.js ecosystem.
Challenge 1: Create a Simple AppIn this challenge, students create a Hapi.js server with a single route that responses to a GET request.
Challenge 1: SolutionRyan walks through the solution to Challenge 1 and answers questions from students.
Routes and Route Handlers
Rest API PrinciplesAfter reviewing principles of Rest API, Ryan discusses configuring routes with Hapi.js.
Challenge 2: Setting Up RoutesIn this challenge, students create two routes: one route to get data and another route to get a single object from within that data.
Challenge 2: SolutionRyan walks through the solution to Challenge 1 and answers questions from students.
PrerequisitesWhen building an API, there are common tasks that need to be handled before a route is sent to a client: pull data out of a database and save new information; call other APIs and services, and run resource intensive calculations or tasks. Ryan illustrates how HapiJS provides these services called route prerequisites.
Challenge 3: Creating Route PrerequisitesIn this challenge, students add data with an API using two route prerequisites to check if data already exists and then prepare the data to be added to a handler.
Challenge 3: SolutionRyan walks through the solution to Challenge 3.
Boom LibraryDiscussing the types of errors that an application needs to provide, Ryan shows how boom library can help by providing a set of utilities for returning HTTP errors.
Challenge 4: Return ErrorsIn this challenge, students use Boom to return a message when an application finds a mistake.
Challenge 4: SolutionRyan walks through the solution to Challenge 4.
Joi ModuleValidating data helps make applications stable and secure. Ryan demonstrates how the Joi module can verify data with HapiJS.
Challenge 5: Validating RoutesIn this challenge, students use Joi to add validation to routes.
Challenge 5: SolutionRyan walks through the solution to Challenge 5.
Plugin EcosystemTaking a look at the HapiJS developer ecosystem, Ryan reviews plugins that serve many needs for application development including authenticiation, localization, documentation, and templating.
Challenge 6: Using PluginsIn this challenge, students install and test two HapiJS plugins.
Challenge 6: SolutionRyan walks through the solution to Challenge 6.