DEV Community

Robert Rees
Robert Rees

Posted on

HapiJS: Routing notes

I've slowly been exploring HapiJS as an alternative to the standard use of Express.

Routes are built in the Hapi by passing a Route configuration object to the server.route function. The object is validated when the route is being constructed so you do get some feedback if you pass the wrong values.

Binding the handler to the route seems to make the assumption that the route is going to be bound within the server declaration (as you may need to access the server object).

Surprisingly path generation seems to be string-based with no in-built equivalent of Flask's url_for.

There is a recommended plugin akaya but by default it generates absolute URLs and was very confused on the Glitch project I was using to test it.

I didn't find the documentation about the route object that helpful when I needed something beyond the usual key elements.

Top comments (0)