Creating axios instance doesn't append specified config params
See original GitHub issueSummary
I’m using ts-jest
for unit-testing, which means I don’t know if the error still occurs outside the jest
environment.
Basically I’m creating a new instance using the script below. 9/10 times the params doesn’t get appended to the url.
this.api = axios.create({
baseURL: 'https://api.themoviedb.org/3',
params: {
api_key: 'api key goes here',
language: 'da-DK',
append_to_response: 'external_ids,videos'
}
});
Using the request interceptor I logged the config output which was this:
{ adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ common: { Accept: 'application/json, text/plain, */*' },
delete: {},
get: {},
head: {},
post: { 'Content-Type': 'application/x-www-form-urlencoded' },
put: { 'Content-Type': 'application/x-www-form-urlencoded' },
patch: { 'Content-Type': 'application/x-www-form-urlencoded' } },
method: 'get',
baseURL: 'https://api.themoviedb.org/3',
params: undefined,
url: 'movie/427641' }
and as you can see, the params are undefined.
For now I’ve managed to workaround it by defining the params in the interceptor:
this.api.interceptors.request.use(config => ({
...config,
params: {
// ...
},
}));
Context
- axios version: latest
- Environment: node v9.11.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:5
Top Results From Across the Web
Default query params not getting passed in axios request
I solved it using 2 ways: Using default params and spreading them when using the request export const API_DEFAULT_PARAMS = { part: 'part', ......
Read more >Request Config | Axios Docs
These are the available config options for making requests. Only the url is required. Requests will default to GET if method is not...
Read more >Understanding Axios.create
Learn why and how to effectively use Axios.create in your next project with this in-depth tutorial and example build.
Read more >Complete Guide to Axios HTTP Client
An Axios instance created with Axios.create() with a custom config helps us to reuse the provided configuration for all the API invocations made ......
Read more >Sending PUT HTTP Requests with Axios
The more generic axios() call is more flexible since all options/configs are specified within the same object, making it easier to add more ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue, it seems like there’s a PR with a fix #2196
tried changing dependency to 0.18 in package.json but still not working for me ? Am I missing something?