How do I create configuration for axios for default request headers in every http call?
Clash Royale CLAN TAG#URR8PPP
How do I create configuration for axios for default request headers in every http call?
https://github.com/MrFiniOrg/AxiosQuestion
I would like to have my project setup so that I do not have to specify the same request header in every http call.
I have searched this online but I have not been able to accomplish this in my project.
Would someone please assist me in resolving this issue I am having.
I am new to react and axios and I am not sure how to configure this.
My project seems to be doing this but it is sending the request 2 times.
One with the header and one without.
My axios call can be found in the app.js class component
Please include a Minimal, Complete, and Verifiable example in your question.
– jhpratt
Aug 10 at 22:10
1 Answer
1
You can specify config defaults that will be applied to every request.
Global axios defaults
axios.defaults.baseURL = 'https://api.example.com';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
For more specific info, please visit their docs.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of How does one set global headers in axios?
– Tholle
Aug 10 at 22:08