当前位置: 首页>>代码示例>>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;未经允许,请勿转载。