How to use the axios.request 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 aitexiaoy / Strawberry-Wallpaper / src / get-image / pola.js View on Github external
return new Promise((resolve) => {
        axios.request({
            url,

            // `method` ๆ˜ฏๅˆ›ๅปบ่ฏทๆฑ‚ๆ—ถไฝฟ็”จ็š„ๆ–นๆณ•
            method: 'get', // ้ป˜่ฎคๆ˜ฏ get
            // `onDownloadProgress` ๅ…่ฎธไธบไธ‹่ฝฝๅค„็†่ฟ›ๅบฆไบ‹ไปถ
            onDownloadProgress(progressEvent) {
                // ๅฏนๅŽŸ็”Ÿ่ฟ›ๅบฆไบ‹ไปถ็š„ๅค„็†
                console.log('--------------------ไธ‹่ฝฝๅ›พ็‰‡่ฟ›ๅบฆ:')
                // console.log(progressEvent)
            },
        }).then(async (result) => {
            if (result.status === 200) {
                // eslint-disable-next-line no-param-reassign
                result = result.data.data
            } else {
                return
github expo / expo-cli / dev / xdl / src / ApiV2.js View on Github external
// Handle qs
    if (options.queryParameters) {
      reqOptions.params = options.queryParameters;
      reqOptions.paramsSerializer = QueryString.stringify;
    }

    // Handle body
    if (options.body) {
      reqOptions.data = options.body;
    }

    reqOptions = _.merge({}, reqOptions, extraRequestOptions);
    let response;
    let result;
    try {
      response = await axios.request(reqOptions);
      result = response.data;
    } catch (e) {
      const maybeErrorData = idx(e, _ => _.response.data.errors.length);
      if (maybeErrorData) {
        result = e.response.data;
      } else {
        throw e;
      }
    }

    if (result.errors && result.errors.length) {
      let responseError = result.errors[0];
      let error = new ApiV2Error(responseError.message, responseError.code);
      error.serverStack = responseError.stack;
      error.details = responseError.details;
      throw error;
github eunjae-lee / apitool / src / api.ts View on Github external
async requestInternal(
    method: string,
    url: string,
    data: any,
    retry = false,
    retryNum = 0
  ): Promise> {
    if (!retry) {
      this.executeBefores();
    }
    const config: AxiosRequestConfig = this.buildAxiosConfig(method, url, data);
    let response: AxiosResponse | undefined = undefined;
    let ret: Response | undefined = undefined;
    try {
      response = await axios.request(config);
    } catch (e) {
      ret = this.handleException(e);
    } finally {
      removeCancelToken(config.cancelToken);
    }
    if (!ret) {
      ret = await this.transformAndValidateResponse(
        response!,
        method,
        url,
        data,
        retry,
        retryNum
      );
    }
    if (!retry) {
github microsoft / VoTT / src / react / components / common / externalPicker / externalPicker.tsx View on Github external
});

        if (!authHeaderValue || authHeaderValue === "undefined") {
            return;
        }

        customHeaders[uiOptions.authHeaderName] = authHeaderValue;

        const config: AxiosRequestConfig = {
            method: uiOptions.method,
            url: uiOptions.url,
            headers: customHeaders,
        };

        try {
            const response = await axios.request(config);
            const items: IKeyValuePair[] = response.data.map((item) => {
                return {
                    key: interpolate(uiOptions.keySelector, { item }),
                    value: interpolate(uiOptions.valueSelector, { item }),
                };
            });

            this.setState({
                items,
            });
        } catch (e) {
            return;
        }
    }
}
github thombergs / code-examples / pact / pact-react-consumer / src / rest / hero.service.js View on Github external
getHero(heroId) {
        if (heroId == null) {
            throw new Error("heroId must not be null!");
        }
        return axios.request({
            method: 'GET',
            url: `/heroes/${heroId}`,
            baseURL: `${this.baseUrl}:${this.port}`,
            headers: {
                'Accept': 'application/json; charset=utf-8'
            }
        }, adapter).then((response) => {
            const hero = response.data;
            return new Promise((resolve, reject) => {
                try {
                    this._validateIncomingHero(hero);
                    resolve(hero);
                } catch (error) {
                    reject(error);
                }
            });
github Syncano / syncano-node / packages / cli / src / utils / sockets / sockets.js View on Github external
async socketEnvShouldBeUpdated () {
    debug('socketEnvShouldBeUpdated')
    try {
      const resp = await axios.request({
        url: `https://${session.getHost()}/v2/instances/${session.project.instance}/environments/${this.name}/`,
        method: 'GET',
        timeout: 50000,
        headers: {
          'X-Api-Key': session.settings.account.getAuthKey()
        }
      })

      if (resp.data.metadata.checksum === this.getSocketNodeModulesChecksum()) {
        debug('socketEnvShouldBeUpdated', 'env is up to date')
        return false
      }
      return 'PATCH'
    } catch (err) {
      return 'POST'
    }
github vtex-apps / store-graphql / service / credentials.ts View on Github external
export default ({account, workspace, authToken}) => {
  return vtexToken
    ? Promise.resolve(vtexToken)
    : http.request(
      {
        url: `http://router.aws-us-east-1.vtex.io/${account}/${workspace}/tokens/legacy`,
        method: 'GET',
        headers: {Authorization: `bearer ${authToken}`},
      })
      .then(({data}) => vtexToken = data)
}
github theapurvap / syncrypto / src / utilities / FileUtilities.js View on Github external
static uploadFileToGoogleDrive(access_token, setMessage, fileName, data, salt = new ArrayBuffer(), iv = new ArrayBuffer()) {
        setMessage("Starting upload to Google Drive\u2122. Do not close this window.", true);
        return axios.request({
            method: "POST",
            url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable`,
            headers: {
                "Authorization": `Bearer ${access_token}`,
                "X-Upload-Content-Length": data.byteLength + salt.byteLength + iv.byteLength
            },
            data: { name: fileName, description: "File uploaded using Syncrypto (https://github.com/theapurvap/syncrypto)." }
        }).then(response => axios.request({
            method: "POST",
            url: response.headers.location,
            headers: {
                "Authorization": `Bearer ${access_token}`,
                "Content-Type": "multipart/form-data"
            },
            data: new Blob([data, salt, iv])
        })).then(() => setMessage("File uploaded to Google Drive\u2122!", true)).catch(error => {
github undefinedfm / undefined.fm / src / components / Footer.tsx View on Github external
onSubmit={(values, { setSubmitting, setStatus }) => {
                axios
                  .request({
                    url:
                      'https://api.formik.com/submit/undefinedfm/subscribe',
                    method: 'POST',
                    headers: {
                      'Content-Type': 'application/json',
                    },
                    data: {
                      ...values,
                    },
                  })
                  .then(
                    () => {
                      setSubmitting(false);
                      setStatus('Success');
                    },