hapi request object

In hapi, the goal is never to monkey-patch or modify any of the normal Node objects or methods, but only to provide an extra layer around them to access the important parts.

Note

Monkey patching is the method of overriding or extending the behavior of a method. For example, let's create an add function that returns the sum of two numbers:

let add = function (a, b) {
  return a + b;
}

We now want to log in to the console every time this is called, without altering the existing behavior. We would modify it by doing the following:

let oldAdd = add;
add = function (a, b) {
  console.log('add was called…');
  return oldAdd(a, b);
}

Now every time add is called, it will print add was called…, and return the sum just as before. This can be useful ...

Get Getting Started with hapi.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.