How to use the create function from axios

Find comprehensive JavaScript axios.create code examples handpicked from public code repositorys.

81
82
83
84
85
86
87
88
89
90
}

actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))

/** @type {axios.AxiosInstance} */
const instance = axios.create(instanceConfig);

actions.debug('Request Data: ' + JSON.stringify(requestData))

const execRequest = async () => {
fork icon60
star icon185
watch icon4

+ 5 other calls in file

43
44
45
46
47
48
49
50
51
52
53
const { Readable } = require("stream")
const heicConvert = require("heic-convert")
const { Semaphore } = require("await-semaphore")
const progress = require("progress-stream")


const axiosClient = axios.create({
    timeout: 3600000,
    maxContentLength: (((1024 * 1024) * 1024) * 1024),
    maxBodyLength: (((1024 * 1024) * 1024) * 1024),
    httpsAgent: new https.Agent({
fork icon24
star icon118
watch icon8

+ 3 other calls in file

28
29
30
31
32
33
34
35
36
37

assert(signer instanceof Signer);

this._signer = signer;

this._client = axios.create(
  Object.assign(this._clientOptions, {
    headers: {
      'X-Key-Id': keyId,
    },
fork icon6
star icon32
watch icon1

+ 9 other calls in file

9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
  $("#validation_error_accordion").html(accordion_elements);
  // $("#validation_error_accordion").accordion();
};


$("#validate_dataset_bttn").on("click", async () => {
  const axiosInstance = axios.create({
    baseURL: "http://127.0.0.1:5000/",
    timeout: 0,
  });

fork icon9
star icon22
watch icon9

+ 7 other calls in file

16
17
18
19
20
21
22
23
24
25
  DIMS_API_POLL_INTERVAL
} = require('./config')

module.exports = exports = {}

const client = axios.create({ baseURL: DIMS_API_URL })
let token = ''
let walletInfo
// let socket
let checkIsRunning = false
fork icon2
star icon2
watch icon5

157
158
159
160
161
162
163
164
165
166
}

//=================================================================================================
// Initialize Axios Client (this client will be used to communicate with the device)			===
//=================================================================================================
this.syrApiClient = axios.create({
	baseURL: `http://${this.config.device_ip}:${this.config.device_port}/safe-tec/`,
	timeout: timeout_axios_request * 1000,
	responseType: 'json',
	responseEncoding: 'utf8',
fork icon1
star icon3
watch icon2

+ 3 other calls in file

104
105
106
107
108
109
110
111
112
113
114
115
app.use(cookieParser());
// for parsing application/xwww-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));


function createAxiosInstance(req, baseURL, logger, headers) {
    const axiosInstace = axios.create({baseURL, headers});


    axiosInstace.interceptors.response.use(undefined, function (error) {
        logger.log({level: 'error', message: error, errorType: 'http'});
        return Promise.reject(error)
fork icon0
star icon11
watch icon6

+ 3 other calls in file

168
169
170
171
172
173
174
175
176
177

/**
 * Service created lifecycle event handler.
 */
created() {
    this.axios = axios.create({
        baseURL: this.settings.axios.baseURL,
        timeout: this.settings.axios.timeout,
        headers: this.settings.axios.headers
    })
fork icon0
star icon3
watch icon1

42
43
44
45
46
47
48
49
50

if ( !this.options.token ) {
        throw new Error('Token must be passed!');
}

this.movapi = axios.create({
        baseURL: this.options.base_url || "https://api.movidesk.com/public/v1",
        timeout: this.options.timeout || 3000
});
fork icon0
star icon2
watch icon3

258
259
260
261
262
263
264
265
266
267

### Creating an instance

You can create a new instance of axios with a custom config.

##### axios.create([config])

```js
const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
fork icon0
star icon1
watch icon0

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
25

// GitHub API client (both REST and GraphQL)
const octokit = new Octokit({ auth: process.env.GITHUB_API_TOKEN });

// ZenHub API client
const zhApi = axios.create({
  baseURL: 'https://api.zenhub.com/',
  headers: {
    'X-Authentication-Token': process.env.ZENHUB_API_TOKEN,
  },
fork icon59
star icon0
watch icon1

19
20
21
22
23
24
25
26
27
28
const state_attr = require(`${__dirname}/lib/state_attr.js`); // Load attribute library
const isOnline = require('@esm2cjs/is-online').default;
const https = require('https');
const axios = require('axios');
// @ts-ignore
let axiosInstance = axios.create({});

const oneHour = 60 * 60 * 1000;
let polling; // Polling timer
let pooltimer = [];
fork icon11
star icon24
watch icon12

4
5
6
7
8
9
10
11
12
13
const BASE_URL2 = 'https://puzzle.zaih.com'
const BASE_URL3 = 'https://apis-puzzle-new.zaih.com'

module.exports = class Https {
  constructor ({access_token, account_id}) {
    this.request = axios.create({
      headers: {
        ...headers,
        uid: account_id,
        // eslint-disable-next-line camelcase
fork icon394
star icon3
watch icon2

36
37
38
39
40
41
42
43
44
45
 * ## Methods
 */
class GraphQL extends Helper {
  constructor(config) {
    super(config);
    this.axios = axios.create();
    this.headers = {};
    this.options = {
      timeout: 10000,
      defaultHeaders: {},
fork icon706
star icon0
watch icon106

2974
2975
2976
2977
2978
2979
2980
2981
2982
if (this._isInit === true) {
  return 2;
}

const jar = this._cookieJar;
this._instance = axios.create({
  httpAgent: new HttpCookieAgent({cookies: {jar}}),
  httpsAgent: new HttpsCookieAgent({cookies: {jar}, rejectUnauthorized: this.opts.sslverify, requestCert: true})
});
fork icon43
star icon108
watch icon9

+ 2 other calls in file

387
388
389
390
391
392
393
394
395
396

// axiosConfig.baseURL = 'https://httpstat.us';
// axiosConfig.url = '/429';
// axiosConfig.method = 'get';

const myAxiosInstance = axios.create(axiosConfig);

myAxiosInstance.defaults.raxConfig = {
    instance: myAxiosInstance,
};
fork icon2
star icon7
watch icon2

+ 3 other calls in file

242
243
244
245
246
247
248
249
250
251
//=====================================================================================================================
// Initialize Axios Client for SafeFloor Units (this client will be used to communicate with the SafeFloor units)	===
//=====================================================================================================================
if (this.config.safefloor_1_ip != '0.0.0.0' && this.config.safefloor_1_ip != '') {
	this.log.info('SafeFloor Connect Unit 1 IP-Address: ' + String(this.config.safefloor_1_ip) + ':' + String(this.config.device_port));
	this.syrSaveFloor1APIClient = axios.create({
		baseURL: `http://${this.config.safefloor_1_ip}:${this.config.device_port}/floorsensor/`,
		timeout: FloorSensoLoopTimeout * 1000,
		responseType: 'json',
		responseEncoding: 'utf8',
fork icon1
star icon3
watch icon2

+ 4 other calls in file

26
27
28
29
30
31
32
33
34
35
this.poll_check_time = 0;
this.session = {};
this.mqttC = {};
this.mqtt_response_check = {};
this.cookieJar = new tough.CookieJar();
this.requestClient = axios.create({
    withCredentials: true,
    httpsAgent: new HttpsCookieAgent({
        cookies: {
            jar: this.cookieJar,
fork icon1
star icon3
watch icon0

6
7
8
9
10
11
12
13
14
15
16
  DELETE: "DELETE",
};


class AnythinkClient {
  constructor() {
    this.client = axios.create({
      baseURL: "http://localhost:3000",
      timeout: 2000,
    });
  }
fork icon0
star icon1
watch icon0

+ 2 other calls in file

5
6
7
8
9
10
11
12
13
14
15
ipcMain.on("sync-edit-baseUrl", (event, arg) => {
    HttpSetting.httpBaseURL = arg.baseUrl
    event.returnValue = arg
})


const service = axios.create({
    // baseURL: "http://onlinecs.vaiwan.cn/api/",
    baseURL: `${HttpSetting.httpBaseURL}/api/`,
    timeout: 30 * 1000, // 请求超时时间
    maxBodyLength: Infinity, //设置适当的大小
fork icon722
star icon0
watch icon338

+ 4 other calls in file