当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript axios.request函数代码示例

本文整理汇总了TypeScript中axios.request函数的典型用法代码示例。如果您正苦于以下问题:TypeScript request函数的具体用法?TypeScript request怎么用?TypeScript request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了request函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: addBasepath

async function AJAX<T = any>(
  {
    url,
    method = 'GET',
    data = {},
    params = {},
    headers = {},
    auth = null,
  }: RequestParams,
  excludeBasepath = false
): Promise<(T) | AxiosResponse<T>> {
  try {
    url = addBasepath(url, excludeBasepath)

    const response = await axios.request<T>({
      url,
      method,
      data,
      params,
      headers,
      auth,
    })

    return response
  } catch (error) {
    const {response} = error
    throw response
  }
}
开发者ID:influxdata,项目名称:influxdb,代码行数:29,代码来源:ajax.ts

示例2: Promise

  return new Promise((resolve, reject) => {
    let partialBody = '';

    return axios
      .request<IncomingMessage>(config)
      .then(response => {
        if (response.status !== 200) {
          return reject(`Request failed with status code "${response.status}".`);
        }

        const contentType = response.headers['content-type'] || '';
        const isHtmlContentType = contentType.match(/.*text\/html/);

        if (!isHtmlContentType) {
          reject(`Unhandled format for open graph generation ('${contentType}')`);
        }

        response.data.on('data', buffer => {
          const chunk = buffer.toString();
          partialBody += chunk;

          if (chunk.match('</head>') || partialBody.length > contentLimit) {
            cancelSource.cancel();
            resolve(partialBody);
          }
        });

        response.data.on('error', reject);
        response.data.on('end', () => resolve(partialBody));
      })
      .catch(error => (axios.isCancel(error) ? Promise.resolve('') : Promise.reject(error)));
  });
开发者ID:wireapp,项目名称:wire-desktop,代码行数:32,代码来源:openGraph.ts

示例3: async

const fetchImageAsBase64 = async (url: string): Promise<string | undefined> => {
  const IMAGE_SIZE_LIMIT = 5e6; // 5MB

  const axiosConfig: AxiosRequestConfig = {
    headers: {
      'User-Agent': USER_AGENT,
    },
    maxContentLength: IMAGE_SIZE_LIMIT,
    method: 'get',
    responseType: 'arraybuffer',
    url,
  };

  const response = await axios.request<Buffer>(axiosConfig);

  if (response.status !== 200) {
    throw new Error(`Request failed with status code "${response.status}".`);
  }

  const contentType = response.headers['content-type'] || '';
  const isImageContentType = contentType.match(/.*image\/.*/);

  if (!isImageContentType) {
    throw new Error(`Unhandled format for open graph image ('${contentType}')`);
  }

  return bufferToBase64(response.data, contentType);
};
开发者ID:wireapp,项目名称:wire-desktop,代码行数:28,代码来源:openGraph.ts

示例4: makeRequest

function makeRequest(request: AxiosRequestConfig) {
  return axios.request({
    ...request,
    headers: {
      'Content-Type': 'application/json',
    },
  });
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:8,代码来源:requests-middleware.ts

示例5: getUserCanAccessResource

async function getUserCanAccessResource (authToken: string, account: string, userEmail: string, productCode: string, resourceCode: string): Promise<boolean> {
  const url = `http://${account}.vtexcommercestable.com.br/api/license-manager/pvt/accounts/${account}/products/${productCode}/logins/${userEmail}/resources/${resourceCode}/granted`
  const req = await axios.request({
    headers: {
      'Authorization': authToken,
    },
    method: 'get',
    url,
  })
  return req.data
}
开发者ID:vtex,项目名称:apps-client-node,代码行数:11,代码来源:Auth.ts

示例6: sendRequest

 protected sendRequest(method, url, params?): Promise<AxiosResponse> {
   return Axios.request({
     method,
     baseURL: `${this.rabbitmqConfig.mgtHttpTheme}://${this.rabbitmqConfig.mgtHttpHost}:${this.rabbitmqConfig.mgtHttpPort}/api/`,
     url,
     params,
     headers: {'content-type': 'application/json'},
     auth: {
       username: this.rabbitmqConfig.username,
       password: this.rabbitmqConfig.password,
     },
   });
 }
开发者ID:yruan,项目名称:inceptum,代码行数:13,代码来源:RabbitmqMgtHttpApi.ts

示例7: getUserEmail

async function getUserEmail (authToken: string, vtexIdToken: string): Promise<string | void> {
  const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`
  const req = await axios.request({
    headers: {
      'Accept': 'application/json',
      'Proxy-Authorization': authToken,
      'X-VTEX-Proxy-To': `https://${url}`,
    },
    method: 'get',
    url: `http://${url}`,
  })
  if (!req.data) {
    return undefined
  }
  return req.data.user
}
开发者ID:vtex,项目名称:apps-client-node,代码行数:16,代码来源:Auth.ts

示例8: getSubjectDetails

    public getSubjectDetails(subjectIds: string): Promise<Subject[]> {
        const config = {
            ...this.axiosConfig,
            method: "get",
            params: {
                "index": "gnd",
                // lookfor: "[" + contributorIds + "]",
                "method": "getSubjects",
                "overrideIds[]": subjectIds,
                "searcher": "ElasticSearch",
                "type": "DEFAULT",
            },
        };

        return Axios.request(config)
            .then((response: AxiosResponse) => {
                return response.data.data as Subject[];
            });
    }
开发者ID:swissbib,项目名称:vufind,代码行数:19,代码来源:Hydra.ts

示例9: getOrganisationDetails

    public getOrganisationDetails(organisationIds: string): Promise<Organisation[]> {
        const config = {
            ...this.axiosConfig,
            method: "get",
            params: {
                "index": "lsb",
                // lookfor: "[" + contributorIds + "]",
                "method": "getOrganisations",
                "overrideIds[]": organisationIds,
                "searcher": "ElasticSearch",
                "type": "organisation",
            },
        };

        return Axios.request(config)
            .then((response: AxiosResponse) => {
                return response.data.data as Organisation[];
            });
    }
开发者ID:swissbib,项目名称:vufind,代码行数:19,代码来源:Hydra.ts


注:本文中的axios.request函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。