本文整理汇总了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;
},
示例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
}
示例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}`)
}
}
}
示例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
}
示例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();
});
});
}
示例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'
});
});
示例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]);
});
示例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);
}
示例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');
});