concept client in category hapi

appears as: client, clients, client, The client
hapi.js in Action

This is an excerpt from Manning's book hapi.js in Action.

Every request your application receives will go through a lifecycle that interacts with these elements to form a response that is sent back to the client. Figure 1.6 shows a basic overview of this process. Once you grasp what these central building blocks are all about, you’ll understand the overall process that you’ll follow with hapi, no matter what you’re building.

A hapi application’s purpose in life is to serve HTTP requests. At a high level, you take a request and process it, make decisions based on the information in the request, and ultimately build an appropriate response to send back to the client. That’s it. And with any luck, your application keeps on doing that over and over without stopping.

Because getInfo is a handler here, we want it to set a response to the client when we call reply() in this case. Now let’s say we end up writing more routes later, which require this same data. We may decide that we’d like to reuse the same getInfo function as a route prerequisite.

Listing 5.3. Reusing the same function as a prerequisite

In this case, we don’t want reply() in the getInfo function to set a response to the client. We want it to set the result value of the pre in request.pre.info. This is the whole reason behind the slightly different reply() semantics—it allows us to reuse the same functions interchangeably as handlers or pres and have them behave how we’d expect in both instances.

There are many different status codes available to communicate all kinds of scenarios to a client. You can find a full list at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes.