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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay