How to use the axios.create function in axios

To help you get started, weโ€™ve selected a few axios examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github micky2be / superlogin-client / src / index.js View on Github external
configure(config = {}) {
		if (config.serverUrl) {
			this._http = axios.create({
				baseURL: config.serverUrl,
				timeout: config.timeout
			});
		}

		config.baseUrl = config.baseUrl || '/auth';
		config.baseUrl = config.baseUrl.replace(/\/$/, ''); // remove trailing /
		config.socialUrl = config.socialUrl || config.baseUrl;
		config.socialUrl = config.socialUrl.replace(/\/$/, ''); // remove trailing /
		config.local = config.local || {};
		config.local.usernameField = config.local.usernameField || 'username';
		config.local.passwordField = config.local.passwordField || 'password';

		if (!config.endpoints || !(config.endpoints instanceof Array)) {
			config.endpoints = [];
		}
github renrenio / renren-fast-vue / src / utils / httpRequest.js View on Github external
import Vue from 'vue'
import axios from 'axios'
import router from '@/router'
import qs from 'qs'
import merge from 'lodash/merge'
import { clearLoginInfo } from '@/utils'

const http = axios.create({
  timeout: 1000 * 30,
  withCredentials: true,
  headers: {
    'Content-Type': 'application/json; charset=utf-8'
  }
})

/**
 * ่ฏทๆฑ‚ๆ‹ฆๆˆช
 */
http.interceptors.request.use(config => {
  config.headers['token'] = Vue.cookie.get('token') // ่ฏทๆฑ‚ๅคดๅธฆไธŠtoken
  return config
}, error => {
  return Promise.reject(error)
})
github LeaPhant / skyblock-stats / index.js View on Github external
const db = low(adapter);

const CACHE_DURATION = 30 * 24 * 60 * 60 * 1000; // 30 days

db
.defaults({ usernames: [], profiles: [] })
.write();

fs.ensureDirSync('cache');

const credentials = require('./credentials.json');

if(credentials.hypixel_api_key.length == 0)
    throw "Please enter a valid Hypixel API Key. Join mc.hypixel.net and enter /api to obtain one.";

const Hypixel = axios.create({
    baseURL: 'https://api.hypixel.net/'
});

let api_index = 0;
let api_key = credentials.hypixel_api_key;

if(!Array.isArray(api_key))
    api_key = [api_key];

function getApiKey(){
    api_index++;

    if(api_index >= api_key.length)
        api_index = 0;

    return api_key[api_index];
github dreamnettech / dreamtime / src / gui / pages / update.vue View on Github external
created() {
    this.http = axios.create({
      baseURL: hostURL
    })

    this.fetchReleases()
  },
github okachijs / jsframeworkbook / 3_6_react / src_making / v0.9 / client.ts View on Github external
import Axios, { AxiosInstance, AxiosResponse, CancelToken } from 'axios';

const baseURL = 'https://us-central1-demoapp-1779c.cloudfunctions.net/v1';


const instance: AxiosInstance = Axios.create({
    baseURL,
    timeout: 10000
});

export interface Message {
    id?: string;
    body?: string;
    user?: {
        id: string
        name: string
        avatar: string
    };
    date?: string;
}

export const fetchMessages = (channelName: string, params = {}, cancelToken: CancelToken = null): Promise> => {
github FrontSpot-Community / code-battle / src / common / services / httpClient / httpClient.js View on Github external
constructor(baseUrl) {
    this.baseUrl = baseUrl;

    this.service = axios.create({
      baseURL: this.baseUrl,
      headers: {
        'Content-Type': 'application/json; charset=UTF-8'
      },
      withCredentials: true
    });

    this.service.interceptors.response.use(
      responseSuccessInterceptor,
      responseFailureInterceptor
    );
  }
github egovernments / egov-services / web / react-pgr-web-v2 / src / components / non-framework / citizenServices / wc / view.js View on Github external
this.setState({
        RequestInfo: {
          "apiId": "org.egov.pt",
          "ver": "1.0",
          "ts": new Date().getTime(),
          "action": "asd",
          "did": "4354648646",
          "key": "xyz",
          "msgId": "654654",
          "requesterId": "61",
          "authToken": localStorage.token,
          "userInfo": JSON.parse(localStorage.userRequest)
        }
    })

    var instance = axios.create({
      baseURL: window.location.origin,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Basic ZWdvdi11c2VyLWNsaWVudDplZ292LXVzZXItc2VjcmV0',
      }
    });

    /*var params = new URLSearchParams();
    params.append('username', "murali");
    params.append('password', "12345678");
    params.append('grant_type', 'password');
    params.append('scope', 'read');
    params.append('tenantId', window.localStorage.getItem("tenantId"));
    instance.post('/user/oauth/token', params).then(function(response) {
      localStorage.setItem("request-temp", JSON.stringify(response.data.UserRequest));
      localStorage.setItem("auth-token-temp", response.data.access_token);*/
github topheman / npm-registry-browser / src / services / apis / httpClient.js View on Github external
export const makeClient = ({
  retries = 3,
  retryDelay = fibonacciRetryDelay(),
  ...axiosConfig
}) => {
  const client = axios.create(axiosConfig);
  /*
   * If the network or the api server fails a request, the client will
   * retry 3 times until the request goes through
   * Only applied to idempotent requests:
   * - method GET/HEAD/OPTIONS/PUT/DELETE
   * - 5xx server error
   * - network errors
   */
  if (retries) {
    axiosRetry(client, { retries, retryDelay });
  }
  return client;
};
github Yoctol / messaging-apis / packages / messaging-api-line / src / LinePay.ts View on Github external
constructor({
    channelId,
    channelSecret,
    sandbox = false,
    origin,
  }: Types.LinePayConfig) {
    const linePayOrigin = sandbox
      ? 'https://sandbox-api-pay.line.me'
      : 'https://api-pay.line.me';

    this._axios = axios.create({
      baseURL: `${origin || linePayOrigin}/v2/`,
      headers: {
        'Content-Type': 'application/json',
        'X-LINE-ChannelId': channelId,
        'X-LINE-ChannelSecret': channelSecret,
      },
    });
  }
github zpnk / stage-ci / core.js View on Github external
const log = require('./logger');

if (!process.env.GITHUB_TOKEN) {
  throw new Error('GITHUB_TOKEN must be defined in environment');
}

if (!process.env.NOW_TOKEN) {
  throw new Error('NOW_TOKEN must be defined in environment');
}

const now = (cmd='') => {
  const nowBin = path.resolve('./node_modules/now/build/bin/now');
  return `${nowBin} ${cmd} --token ${process.env.NOW_TOKEN}`;
};

const githubApi = axios.create({
  headers: {
    'Authorization': `token ${process.env.GITHUB_TOKEN}`
  }
});

function stage(cwd, {alias}) {
  return new Promise((resolve, reject) => {
    const nowProc = exec(now(), {cwd});
    nowProc.stderr.on('data', (error) => reject(new Error(error)));
    nowProc.stdout.on('data', (url) => {
      if (!url) return;
      log.info(`> Aliasing ${url}`);
      const aliasProc = exec(now(`alias set ${url} ${alias}`), {cwd});
      aliasProc.on('data', (error) => reject(new Error(error)));
      aliasProc.on('close', (code) => {
        log.info(`> Alias ready ${alias}`);