本文整理汇总了TypeScript中got.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: get
export function get(url: string, headers: any): Promise<any> {
headers["User-Agent"] = userAgent;
return got
.get(url, { headers })
.then((res: any) => parseJSON(res.body))
.catch(wrapError);
}
示例2: test
test('promise mode', async (t) => {
t.is((await got.get(s.url)).body, 'ok');
try {
await got.get(`${s.url}/404`);
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.response.body, 'not found');
}
try {
await got.get('.com', {retries: 0});
t.fail('Exception was not thrown');
} catch (err) {
t.truthy(err);
}
});
示例3: getUpdateYaml
async function getUpdateYaml(): Promise<string> {
const targetUrl = getUpdateCheckUrl();
const { body } = await get(targetUrl, getGotOptions());
if (!body) {
throw new Error('Got unexpected response back from update check');
}
return body.toString('utf8');
}
示例4: downloadUpdate
export async function downloadUpdate(
fileName: string,
logger: LoggerType
): Promise<string> {
const baseUrl = getUpdatesBase();
const updateFileUrl = `${baseUrl}/${fileName}`;
const signatureFileName = getSignatureFileName(fileName);
const signatureUrl = `${baseUrl}/${signatureFileName}`;
let tempDir;
try {
tempDir = await createTempDir();
const targetUpdatePath = join(tempDir, fileName);
const targetSignaturePath = join(tempDir, getSignatureFileName(fileName));
logger.info(`downloadUpdate: Downloading ${signatureUrl}`);
const { body } = await get(signatureUrl, getGotOptions());
await writeFile(targetSignaturePath, body);
logger.info(`downloadUpdate: Downloading ${updateFileUrl}`);
const downloadStream = stream(updateFileUrl, getGotOptions());
const writeStream = createWriteStream(targetUpdatePath);
await new Promise((resolve, reject) => {
downloadStream.on('error', error => {
reject(error);
});
downloadStream.on('end', () => {
resolve();
});
writeStream.on('error', error => {
reject(error);
});
downloadStream.pipe(writeStream);
});
return targetUpdatePath;
} catch (error) {
if (tempDir) {
await deleteTempDir(tempDir);
}
throw error;
}
}
示例5: test
test('GET can have body', async (t) => {
const {body, headers} = await got.get(s.url, {body: 'hi'});
t.is(body, 'hi');
t.is(headers.method, 'GET');
});