Stephan Max
Stephan Max

Reputation: 147

Expose hapi plugin methods via server.expose or server.method

We are using Hapi as our API framework and put everything related to our persistent storage backend (mongo via mongoose) in a plugin. Now I am wondering how to best expose all the CRUD methods for the different collections (users, notifications, purchases, etc.) to our other API plugins.

I know about server.expose and server.method (Is that just server.expose with caching?) and just can't decide which I should go for in this case. Can you make a recommendation?

Much appreciated!

Upvotes: 3

Views: 758

Answers (1)

Nuri Hodges
Nuri Hodges

Reputation: 888

They are not the same thing.

server.expose is a way to read or update the exposed values of a plugin. Usually used for communicating state between plugins and/or the main Hapi app.

server.method is for exposing methods, and has an ecosystem for handling failure, and as you said, caching.

I think in this case, you would probably opt for server methods.

Upvotes: 6

Related Questions