當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript axios.AxiosInstance類代碼示例

本文整理匯總了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;未經允許,請勿轉載。