Hapi: QUESTION: Calling internal routes.

Created on 26 Feb 2013  Â·  15Comments  Â·  Source: hapijs/hapi

We love the batch routes reature of Hapi, but we are curious if there is (or will be) a way to call internal routes. Seems like an awesome way to create abstraction without having to make http requests to your own server.

Thanks!

support

Most helpful comment

It's a 40 page doc... I am still finding "new" feature I added myself a year ago...

All 15 comments

Example?

Such as:

I have an internal api that is exposed externally via http. If I call /api/some-route, and that route combines several objects (such as from the route /api/some-other-route-object-src ) to return a public facing JSON object, I would like to call that route without having to make an external http request.

Right now, we use the Request library from Mikael. So we do something like this:

request.get('http://my.server.com/api/some-other-route-object-src', function () {
    //
});

But, we would like to do:

function routeHandler (request) {
    request.internalRoute.get('/api/some-other-route-object-src', function () {
        //
    });
}

Just the though of being able to invoke GET, POST, PUT, and DELETE routes internally seems like it could solve some modular complexities and remove the need to make http requests to your own server.

WOW. I just feel dumb now. I feel like I combed through your docs over and over.

Thanks for your patience!

It's a 40 page doc... I am still finding "new" feature I added myself a year ago...

For any other lost soul who happily ends up here, I believe the relevant URL for request injection is now:

https://github.com/hapijs/hapi/blob/master/docs/Reference.md#serverinjectoptions-callback

All these examples 404, could someone post a new link please? =)

Here is the new location of the link mentioned above:
http://hapijs.com/api#serverinjectoptions-callback

You may find this useful too:
https://www.youtube.com/watch?v=ppK47d2Uta4

Thank you @gergoerdosi =)

changed again, to https://hapijs.com/api#-await-serverinjectoptions

that's a lot of changes

As of January 2020: https://hapi.dev/api/?v=19.0.4#-await-serverinjectoptions

As of Feb 2020, v19.10: https://hapi.dev/api/?v=19.1.0#-await-serverinjectoptions

We're working on fixing the links issue...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AdriVanHoudt picture AdriVanHoudt  Â·  5Comments

shamsher31 picture shamsher31  Â·  5Comments

jney picture jney  Â·  4Comments

leore picture leore  Â·  4Comments

jeffbski picture jeffbski  Â·  5Comments