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


TypeScript AxiosInstance.get方法代碼示例

本文整理匯總了TypeScript中axios.AxiosInstance.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AxiosInstance.get方法的具體用法?TypeScript AxiosInstance.get怎麽用?TypeScript AxiosInstance.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在axios.AxiosInstance的用法示例。


在下文中一共展示了AxiosInstance.get方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: switch

  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

示例6: it

 it('should work #2', async () => {
     const response = await client.get('/notes/222');
     expect(response.status).toBe(200);
     expect(response.data).toEqual({
         id: 222,
         text: 'Note #222'
     });
 });
開發者ID:loki2302,項目名稱:nodejs-experiment,代碼行數:8,代碼來源:e2e.spec.ts

示例7: it

 it('should work', async () => {
     const results = [];
     for(let i = 0; i < 8; ++i) {
         const response = await client.get('/');
         results.push(response.status);
     }
     expect(results).to.deep.equal([200, 200, 200, 200, 200, 429, 429, 429]);
 });
開發者ID:loki2302,項目名稱:nodejs-experiment,代碼行數:8,代碼來源:express-rate-limit.spec.ts

示例8: get

    /**
     * Returns a collection
     */
    public get(query: GetQuery): AxiosPromise<Collection> {
        let params = {
            method: "GET",
            params: query,
        };

        return this.httpClient.get<Collection>(this.url, params);
    }
開發者ID:apioo,項目名稱:psx-api,代碼行數:11,代碼來源:typescript.ts

示例9: it

 it('should respond with 200 when there is token', async () => {
     const token = jwt.sign({ name: 'medved' }, JWT_SECRET);
     const response = await client.get('/', {
         headers: {
             authorization: 'Bearer ' + token
         }
     });
     expect(response.status).to.equal(200);
     expect(response.data).to.equal('hello world! medved');
 });
開發者ID:loki2302,項目名稱:nodejs-experiment,代碼行數:10,代碼來源:passport-jwt.spec.ts


注:本文中的axios.AxiosInstance.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。