Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with hapi.js

You're reading from  Getting Started with hapi.js

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781785888182
Pages 156 pages
Edition 1st Edition
Languages

Server routing


There are many ways to interpret a route in terms of web servers, but the easiest (or what I like to think of them as) one is the path that interacts with a particular resource on a web server. In most frameworks, including hapi, a route comprises three core properties:

  • the path through which you can access the route

  • a method by which you can access the path

  • a handler, which is a function to take an action based on the request and return the output to the user

In hapi, the handler looks like the following:

…
server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    return reply('Hello!');
  }
});
…

The preceding code should look familiar to the code sample of our server from the previous chapter. Again, like everything in hapi, we add a route by providing a configuration object with the required route properties. If any required properties are missing, the server will show an error on startup with a detailed error message, thus making it very easy to...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}