Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide global config for axios instance #846

Closed
artworkad opened this issue Jul 5, 2018 · 6 comments
Closed

Provide global config for axios instance #846

artworkad opened this issue Jul 5, 2018 · 6 comments

Comments

@artworkad
Copy link

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

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jul 24, 2018

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

@Sharique-Hasan
Copy link

When can this be available?

@vdyalex
Copy link

vdyalex commented Aug 20, 2018

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

@tonivj5
Copy link

tonivj5 commented Aug 20, 2018

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

@kamilmysliwiec
Copy link
Member

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!

@lock
Copy link

lock bot commented Sep 24, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants