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

TypeScript axios.AxiosInstance类代码示例

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

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



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

示例1: httpExport

 public async httpExport(uri: string, targetPath: string): Promise<string> {
   await this.client.head(uri)
   const response = await this.client.get(uri, { responseType: 'stream' })
   const req = response.data.pipe(createWriteStream(targetPath))
   await new Promise((resolve) => req.on('finish', resolve))
   return targetPath
 }
开发者ID:uetchy,项目名称:niconico,代码行数:7,代码来源:nicovideo.ts


示例2: Error

  private _makeRequest<T>(method: string, url: string, queryParams?: object, body?: object) {
    let request: AxiosPromise<T>;
    switch (method) {
      case 'GET':
        request = this._httpClient.get<T>(url, {params: queryParams});
        break;
      case 'POST':
        request = this._httpClient.post<T>(url, body, {params: queryParams});
        break;
      case 'PUT':
        request = this._httpClient.put<T>(url, body, {params: queryParams});
        break;
      case 'PATCH':
        request = this._httpClient.patch<T>(url, body, {params: queryParams});
        break;
      case 'DELETE':
        request = this._httpClient.delete(url, {params: queryParams});
        break;

      default:
        throw new Error('Method not supported');
    }
    return new Observable<T>(subscriber => {
      request.then(response => {
        subscriber.next(response.data);
        subscriber.complete();
      }).catch((err: Error) => {
        subscriber.error(err);
        subscriber.complete();
      });
    });
  }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:32,代码来源:rxios.ts


示例3: async

  get: async (url: string, config?: AxiosRequestConfig) => {
    if (config) {
      config.url = url;
    }
    const fingerprint = JSON.stringify(config || url);
    const isNeedCache = !whitelist.length || whitelist.includes(url);
    const hashKey = hash
      .sha256()
      .update(fingerprint)
      .digest('hex');

    if (expiry !== 0) {
      const cached = sessionStorage.getItem(hashKey);
      const lastCachedTS: number = +sessionStorage.getItem(`${hashKey}:TS`);
      if (cached !== null && lastCachedTS !== null) {
        const age = (Date.now() - lastCachedTS) / 1000;
        if (age < expiry) {
          return JSON.parse(cached);
        }
        sessionStorage.removeItem(hashKey);
        sessionStorage.removeItem(`${hashKey}:TS`);
      }
    }

    const rsp = await instance.get(url, config);

    if (isNeedCache) {
      cacheRsp(rsp, hashKey);
    }
    return rsp;
  },
开发者ID:SteveTannnnng,项目名称:Mob,代码行数:31,代码来源:request.ts


示例4: configure

  static async configure(enabled: boolean, url: string, logger: sdk.Logger) {
    if (enabled) {
      const proxyConfig = process['PROXY'] ? { httpsAgent: new httpsProxyAgent(process['PROXY']) } : {}

      this.client = Axios.create({
        baseURL: url,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        ...proxyConfig
      })

      const ducklingDisabledMsg = `, so it will be disabled.
For more informations (or if you want to self-host it), please check the docs at
https://botpress.io/docs/build/nlu/#system-entities
`

      try {
        const { data } = await this.client.get('/')
        if (data !== 'quack!') {
          return logger.warn(`Bad response from Duckling server ${ducklingDisabledMsg}`)
        }
        this.enabled = true
      } catch (err) {
        logger.attachError(err).warn(`Couldn't reach the Duckling server ${ducklingDisabledMsg}`)
      }
    }
  }
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:26,代码来源:duckling_extractor.ts


示例5: put

    public put(data: Item): AxiosPromise<Message> {
        let params = {
            method: "PUT",
        };

        return this.httpClient.put<Message>(this.url, data, params);
    }
开发者ID:apioo,项目名称:psx-api,代码行数:7,代码来源:typescript.ts


示例6: createOrder

  public async createOrder(selected: SelectedOptions): Promise<OrderResponse> {
    const request: any = {
      "items": {
        "outward": {
          "journey": selected.outward
        },
        "fares": {}
      }
    };

    if (selected.inward) {
      request.items.inward = { journey: selected.inward };

      if (selected.fareOptions.length === 1) {
        request.items.fares.return = selected.fareOptions[0];
      }
      else {
        request.items.fares.outwardSingle = selected.fareOptions[0];
        request.items.fares.inwardSingle = selected.fareOptions[1];
      }
    }
    else {
      request.items.fares.outwardSingle = selected.fareOptions[0];
    }

    const response = await this.client.post<OrderResponse>("/order", request);

    return response.data;
  }
开发者ID:linusnorton,项目名称:traintickets.to-frontend,代码行数:29,代码来源:OrderService.ts


示例7: thumbinfo

  public async thumbinfo(videoID: string): Promise<IThumbinfo> {
    if (!videoID) {
      throw new Error('videoID must be specified')
    }

    const response = await this.client.get(
      `https://ext.nicovideo.jp/api/getthumbinfo/${videoID}`,
      { responseType: 'text' }
    )
    const result = (await promisify<convertableToString>(parseString)(
      response.data
    )) as any
    if (result.nicovideo_thumb_response.$.status === 'fail') {
      throw new Error(result.nicovideo_thumb_response.error[0].description[0])
    }

    const thumb = result.nicovideo_thumb_response.thumb[0]
    const thumbinfo = {
      description: thumb.description[0],
      movieType: thumb.movie_type[0],
      title: thumb.title[0],
      videoID: thumb.video_id[0],
      watchURL: thumb.watch_url[0],
    } as IThumbinfo
    return thumbinfo
  }
开发者ID:uetchy,项目名称:niconico,代码行数:26,代码来源:nicovideo.ts


示例8: patch

    public patch(data: Item): AxiosPromise<Message> {
        let params = {
            method: "PATCH",
        };

        return this.httpClient.patch<Message>(this.url, data, params);
    }
开发者ID:apioo,项目名称:psx-api,代码行数:7,代码来源:typescript.ts


示例9: delete

    public delete(): AxiosPromise<Message> {
        let params = {
            method: "DELETE",
        };

        return this.httpClient.delete(this.url, params);
    }
开发者ID:apioo,项目名称:psx-api,代码行数:7,代码来源:typescript.ts


示例10: it

 it('should work #1', async () => {
     const response = await client.get('/notes/123');
     expect(response.status).toBe(200);
     expect(response.data).toEqual({
         id: 123,
         text: 'Note #123'
     });
 });
开发者ID:loki2302,项目名称:nodejs-experiment,代码行数:8,代码来源:e2e.spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript axios.AxiosPromise类代码示例发布时间:2022-05-25
下一篇:
TypeScript axios.AxiosAdapter类代码示例发布时间: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