Nest: Provide global config for axios instance

Created on 5 Jul 2018  路  6Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


no global config possible

Expected behavior


In the request library one can specify a global config, e.g.:

return http.defaults({
  headers: {
    'Accept': 'application/json',
    'Content-type': 'application/json',
    'User-agent': 'my-service',
    'x-api-key': 'foobar',
  },
});

axios has the create method, which needs to be implemented

const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

We might do it like this:

imports: [
  HttpModule.forRoot([config])
]

Minimal reproduction of the problem with instructions


n/a

What is the motivation / use case for changing the behavior?

  • I would like to be able to setup a custom header, that should be used for all requests, that leave my nestjs application

Environment


Nest version: X.Y.Z


For Tooling issues:
- Node version: 5.1.0  
- Platform:  Mac 

Others:

n/a

common done 馃憦 type type

Most helpful comment

Fixed by #904. Once merged, following syntax will be available:

HttpModule.register({ ...axios options here });

for example:

HttpModule.register({ timeout: 1 });

1+ need to update the docs

All 6 comments

Fixed by #904. Once merged, following syntax will be available:

HttpModule.register({ ...axios options here });

for example:

HttpModule.register({ timeout: 1 });

1+ need to update the docs

When can this be available?

@kamilmysliwiec, do you have any updates about this feature?

@kamilmysliwiec Why do you use register instead of forRoot? I see the same use, but forRoot is a known method

Because forRoot() suggest that this module shall be registered in the root/app/core module. HttpModule on the other hand, might be used in different places with different configurations.

5.2.0 is here!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artaommahe picture artaommahe  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

tronginc picture tronginc  路  3Comments

KamGor picture KamGor  路  3Comments

hackboy picture hackboy  路  3Comments