Chapter 4. Routes and handlers in-depth

 

This chapter covers

  • More routing techniques
  • Server methods and prerequisites
  • Creating custom handlers
  • Uploading files

In this chapter we’ll take an in-depth look at two of the most important concepts in hapi: routes and handlers. Routes are how you tell hapi what kind of requests you’re interested in. Handlers are how you choose to respond to those routes. Having a mastery of these two will greatly broaden the types of applications you can create with hapi.

4.1. Routing in-depth

You should be familiar now with what routes are in hapi and how to create them (using server.route()). If you’ve been following along with the example projects in earlier chapters, you will have even made quite a few routes yourself. This section attempts to shore up that understanding with a more in-depth examination of routing, including routing features and approaches you haven’t seen yet.

4.1.1. The hapi router: ordering and conflicting routes

In some frameworks, such as Express, the order in which routes are added is significant. In such a framework, if you added two routes in an order contrary to what you intended, you might be left befuddled when things don’t work how you expected.

4.2. Building custom handlers

4.3. Server methods

4.5. Managing file uploads to hapi applications

4.6. Summary

sitemap