How to use the axios.default 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 hcnode / koa-cola / dist / src / util / api.js View on Github external
req.url += (req.url.indexOf('?') == -1 ? '?' : '&') + Object.keys(api.body).map(field => `${field}=${api.body[field]}`).join('&');
        }
    }
    req.url += (req.url.indexOf('?') > -1 ? '&' : '?') + `t=${new Date().valueOf()}`;
    if (ctx) {
        // ๆœฌๅœฐ่ฐƒ็”จ๏ผŒๅนถ้€็ฉฟcookie
        // ๅฐ่ฏ•ไฝฟ็”จrequestๅบ“ๅนถpipeๅฎŒๆ•ด็š„request๏ผŒไฝ†ๆ˜ฏๅ‡บ็Žฐ้—ฎ้ข˜
        req.url = `http://127.0.0.1:${app.config.port}${req.url}`;
        if (ctx.req) {
            var cookie = ctx.req.headers.cookie;
            if (cookie) {
                req.headers.Cookie = cookie;
            }
        }
    }
    var result = await axios_1.default(req);
    api.result = result.data;
    return api;
}
exports.fetch = fetch;
github ruslang02 / atomos / node_modules / google-auth-library / build / src / transporters.js View on Github external
var _this = this;
        // ensure the user isn't passing in request-style options
        opts = this.configure(opts);
        try {
            options_1.validate(opts);
        }
        catch (e) {
            if (callback) {
                return callback(e);
            }
            else {
                throw e;
            }
        }
        if (callback) {
            axios_1.default(opts)
                .then(function (r) {
                callback(null, r);
            })
                .catch(function (e) {
                callback(_this.processError(e));
            });
        }
        else {
            return axios_1.default(opts).catch(function (e) {
                throw _this.processError(e);
            });
        }
    };
    /**
github Codeception / CodeceptJS / lib / helper / REST.js View on Github external
request.auth = this.headers.auth;
    }

    if ((typeof request.data) === 'string') {
      request.headers = Object.assign(request.headers, { 'Content-Type': 'application/x-www-form-urlencoded' });
    }

    if (this.config.onRequest) {
      await this.config.onRequest(request);
    }

    this.debugSection('Request', JSON.stringify(request));

    let response;
    try {
      response = await axios(request);
    } catch (err) {
      if (!err.response) throw err;
      this.debugSection('Response', `Response error. Status code: ${err.response.status}`);
      response = err.response;
    }
    this.debugSection('Response', JSON.stringify(response.data));
    return response;
  }
github aws-amplify / amplify-js / packages / aws-amplify / lib / API / RestClient.js View on Github external
RestClient.prototype._request = function (params, isAllResponse) {
        if (isAllResponse === void 0) { isAllResponse = false; }
        return axios_1.default(params)
            .then(function (response) { return isAllResponse ? response : response.data; })
            .catch(function (error) {
            logger.debug(error);
            throw error;
        });
    };
    RestClient.prototype._parseUrl = function (url) {
github Waifu-pics / waifu-api / src / client / src / functions / api.js View on Github external
getOne: (endpoint, nsfw, callback) => {
    Axios({
      method: "get",
      url: `/api/${nsfw ? "nsfw" : "sfw"}/${endpoint}`,
    }).then((response) => {
      callback(response.data)
    })
  },
  generateImage: (endpoint, nsfw, text, callback) => {
github aws-amplify / amplify-js / packages / aws-amplify / lib / API / RestClient.js View on Github external
secret_key: credentials.secretAccessKey,
            access_key: credentials.accessKeyId,
            session_token: credentials.sessionToken,
        };
        var endpointInfo = {
            region: endpoint_region,
            service: endpoint_service,
        };
        var signerServiceInfo = Object.assign(endpointInfo, signerServiceInfoParams);
        var signed_params = Signer_1.default.sign(otherParams, creds, signerServiceInfo);
        if (signed_params.data) {
            signed_params.body = signed_params.data;
        }
        logger.debug('Signed Request: ', signed_params);
        delete signed_params.headers['host'];
        return axios_1.default(signed_params)
            .then(function (response) { return isAllResponse ? response : response.data; })
            .catch(function (error) {
            logger.debug(error);
            throw error;
        });
    };
    RestClient.prototype._request = function (params, isAllResponse) {
github gcanti / elm-ts / lib / Http.js View on Github external
function getPromiseAxiosResponse(config) {
    return axios_1.default(config);
}
function requestToTask(req) {
github axa-group / Parsr / server / src / input / abbyy / AbbyyClient.ts View on Github external
public soapRequest(url: string, headers: any, xml: any, timeout = 0x7fffffff): Promise {
		const config: axios.AxiosRequestConfig = {
			method: 'post',
			url,
			headers,
			data: xml,
			timeout,
			maxContentLength: Infinity,
			proxy: false,
		};

		const promise: Promise = axios
			.default(config)
			.then(response => {
				if (response.status !== 200) {
					throw new Error(`Unexpected response code ${response.status}, ${response.data}`);
				}

				return response;
			})
			.then(response => {
				return this.parseResponse(response);
			});

		return promise;
	}