hapi-axios
a fun and lightweight integration between hapi and axios
Dependencies
Hapi >= 17.5.3
Axios >= 0.18.0
Usage
- Installation
npm i hapi-axios
- Register
const Hapi = require('hapi');
const HapiAxios = require('hapi-axios');
const server = new Hapi.Server({
host: 'localhost',
port: 4000,
});
await server.register({
plugin: HapiAxios,
options: {
instances: [
{
name: 'typicode',
axios: {
baseURL: 'https://jsonplaceholder.typicode.com',
},
},
],
},
});
await server.start();
- Usage
server.route({
handler: async (request, h) => {
const { typicode } = request.server.plugins['hapi-axios'];
const { data } = await typicode.get('users');
return h.response(data);
},
method: 'GET',
path: '/users',
});