• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript axios.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: callApi

export default function callApi (options) {
  if (typeof options === 'string') options = { url: options }
  options.headers = options.headers || {}

  options.url = API_URL + '/' + options.url

  // pagination
  if (options.page && options.itemsPerPage) {
    const to = (options.page || 1) * options.itemsPerPage - 1
    const from = to - options.itemsPerPage + 1
    // this.header['Range-Unit'] = 'items'
    options.headers['Range'] = `${from || 0}-${to || ''}`
  }

  // single
  if (options.single) {
    options.headers['Prefer'] = 'plurality=singular'
  }

  return axios(options)
  .then(res => {
    const contentRange = res.headers['content-range']
    const json = res.data
    if (json && Array.isArray(json) && contentRange) {
      const range = ContentRangeStructure.exec(contentRange)
      if (range) {
        // const start = parseInt(range[1])
        // const end = parseInt(range[2])
        const total = parseInt(range[3])
        return [json, total]
      }
    }
    return json
  })
}
开发者ID:isairz,项目名称:yomiko,代码行数:35,代码来源:callApi.ts


示例2: processTransaction

const fetchCharge = (localCharge: CoinbaseCharge) => {
	/**
	 * Skip all pending charges that are not at least 3 minutes old
	 * because we know it will take longer than that for Coinbase to process
	 */
	if (!localCharge.code) return;
	const seconds = timeElapsedInSeconds(localCharge.created_at);
	if (seconds < 180) return;

	const config: AxiosRequestConfig = {
		url: `https://api.commerce.coinbase.com/charges/${localCharge.code}`,
		method: 'get',
		headers: {
			'X-CC-Api-Key': `${process.env.COINBASE_API_KEY}`,
			'X-CC-Version': '2018-03-22'
		}
	};

	axios(config)
		.then(async (response: any) => {
			await processTransaction(response.data.data as CoinbaseCharge, localCharge);
		})
		.catch(function (error) {
			console.log(error);
		});
};
开发者ID:joseabril25,项目名称:nem-coinbase-token-sale-api,代码行数:26,代码来源:coinbase-service.ts


示例3: axios

 const response = yield call(() => {
   // tslint:disable-next-line:no-console
   return axios({
     method: 'get',
     url: '/api/animals'
   });
 });
开发者ID:stevejhiggs,项目名称:macgyver,代码行数:7,代码来源:sagas.ts


示例4: axios

export async function import_dashboard(url: string) : Promise<any> {
  let api_url = get_api_url(url)
  log.info(`Importing dashboard from ${api_url}...`)

  // TODO: this is duplicated from query.ts
  let axios_config : any = {
    url: api_url.toString(),
    method: 'get'
  }

  let auth = config.GRAPHITE_AUTH ? config.GRAPHITE_AUTH.trim() : ''
  if (auth) {
    let [username, password] = auth.split(':')
    axios_config.auth = {
      username: username,
      password: password
    }
    axios_config.withCredentials = true
  }

  return axios(axios_config)
    .then(response => translate(response.data.state))
    .then(dash => {
      return manager.client.dashboard_create(dash)
        .then(response => {
          return response
        })
        .catch(error => {
          manager.error(`Error creating dashboard. ${error}`)
        })
    })
}
开发者ID:urbanairship,项目名称:tessera,代码行数:32,代码来源:graphite.ts


示例5: pins

export function pins(
  swlng: number,
  swlat: number,
  nelng: number,
  nelat: number,
  pinTypes: PIN_TYPE[] = [PIN_TYPE.stop]
): Promise<IPin[]> {
  const sw = utils.WGS84toWm(swlng, swlat);
  const ne = utils.WGS84toWm(nelng, nelat);

  let url = "https://www.dvb.de/apps/map/pins?showLines=true";
  pinTypes.forEach((type) => (url += `&pintypes=${type}`));
  const options: AxiosRequestConfig = {
    url,
    params: {
      swlng: sw[0],
      swlat: sw[1],
      nelng: ne[0],
      nelat: ne[1],
    },
    responseType: "text",
    timeout: 5000,
  };

  return axios(options)
    .then((response) => {
      return response.data || [];
    })
    .then((elements) => elements.map((elem: string) => utils.parsePin(elem)));
}
开发者ID:kiliankoe,项目名称:dvbjs,代码行数:30,代码来源:pins.ts


示例6: getState

 (_, getState) =>
   getState().auth && axios({
     method: "post",
     url: API.current.accountResetPath,
     data: payload,
   })
     .then(() => alert(t("Account has been reset.")))
     .catch((err: UnsafeError) => toastErrors({ err }));
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:8,代码来源:actions.ts


示例7: axios

 return packages.map((obj: { name: string }) =>
   axios({
     baseURL: `${constants.API_URL}`,
     url: `/${encodeURIComponent(obj.name)}`,
     method: 'GET',
     validateStatus: (status: number) =>
       (status >= 200 && status < 300) || status === 404,
   })
开发者ID:ekonstantinidis,项目名称:npm-click,代码行数:8,代码来源:index.ts


示例8: monitor

export function monitor(
  stopID: string,
  offset = 0,
  amount = 0
): Promise<IMonitor[]> {
  const now = new Date();
  const time = new Date(now.getTime() + offset * 60 * 1000);

  const options: AxiosRequestConfig = {
    url: "https://webapi.vvo-online.de/dm",
    params: {
      format: "json",
      stopid: stopID,
      time: time.toISOString(),
      isarrival: false,
      limit: amount,
      shorttermchanges: true,
      mentzonly: false,
    },
    timeout: 5000,
  };

  return axios(options)
    .then((response) => {
      // check status of response
      utils.checkStatus(response.data);

      if (response.data.Departures) {
        return response.data.Departures.map((d: any) => {
          const arrivalTime = utils.parseDate(
            d.RealTime ? d.RealTime : d.ScheduledTime
          );
          const scheduledTime = utils.parseDate(d.ScheduledTime);

          return {
            arrivalTime,
            scheduledTime,
            id: d.Id,
            line: d.LineName,
            direction: d.Direction,
            platform: utils.parsePlatform(d.Platform),
            arrivalTimeRelative: dateDifference(now, arrivalTime),
            scheduledTimeRelative: dateDifference(now, scheduledTime),
            delayTime: dateDifference(scheduledTime, arrivalTime),
            state: d.State ? d.State : "Unknown",
            mode: utils.parseMode(d.Mot),
            diva: utils.parseDiva(d.Diva),
          };
        });
      }

      return [];
    })
    .catch(utils.convertError);
}
开发者ID:kiliankoe,项目名称:dvbjs,代码行数:55,代码来源:monitor.ts


示例9: async

const callApi = async (options: AxiosRequestConfig) => {
  try {
    const response = await axios(options);
    return response.data.data;
  } catch (e) {
    if (e.response && e.response.data && e.response.data.errors) {
      e.message = values(e.response.data.errors)[0];
    }
    throw e;
  }
};
开发者ID:ghoullier,项目名称:codesandbox-cli,代码行数:11,代码来源:api.ts


示例10: pointFinder

async function pointFinder(
  name: string,
  stopsOnly: boolean,
  assignedStops: boolean
): Promise<IPoint[]> {
  if (typeof name !== "string") {
    throw utils.constructError("ValidationError", "query has to be a string");
  }

  const stopName = name.trim();

  const options: AxiosRequestConfig = {
    url: "https://webapi.vvo-online.de/tr/pointfinder",
    params: {
      format: "json",
      stopsOnly,
      assignedStops,
      limit: 0,
      query: stopName,
      dvb: true,
    },
    timeout: 5000,
  };

  return axios(options)
    .then((response) => {
      // check status of response
      utils.checkStatus(response.data);

      if (response.data.Points) {
        return response.data.Points.map((p: string) => {
          const poi = p.split("|");

          const city = poi[2] === "" ? "Dresden" : poi[2];
          const idAndType = utils.parsePoiID(poi[0]);
          const coords = utils.WmOrGK4toWGS84(poi[5], poi[4]);

          if (coords) {
            const point: IPoint = {
              city,
              coords,
              name: poi[3].replace(/'/g, ""),
              id: idAndType.id,
              type: idAndType.type,
            };
            return point;
          }
        }).filter((p: IPoint) => p && p.name);
      }

      return [];
    })
    .catch(utils.convertError);
}
开发者ID:kiliankoe,项目名称:dvbjs,代码行数:54,代码来源:find.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript axios.delete函数代码示例发布时间:2022-05-25
下一篇:
TypeScript axios.create函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap