In the first post of the HapiJS series we learned how to
use the server interface to build a server. Today let’s make an API we can use by adding routes and request handlers.
Create a new file like so:
to the server#route function.
You can follow how easy it is to add a route:
Providg a URI for the path
Specify the HTTP method to respond to
Write a handler function for the incoming HTTP request
The first parameter in the handler function is Hapi’s request object. It
encapsulates the data you would expect to have access to like headers, query parameters, and path parameters but includes
other goodies that are part of the Hapi ecosystem too. I suggest looking at the documentation to see what else is
available to you.