本文整理汇总了TypeScript中got类的典型用法代码示例。如果您正苦于以下问题:TypeScript got类的具体用法?TypeScript got怎么用?TypeScript got使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了got类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('accept header with json option', async (t) => {
let headers = (await got(s.url, {json: true})).body;
t.is(headers.accept, 'application/json');
headers = (await got(s.url, {headers: {accept: ''}, json: true})).body;
t.is(headers.accept, '');
});
示例2: got
(async () => {
const repository = process.argv[2];
const response = await got(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repository}:pull`, {
json: true
});
const token = response.body.token;
const allTags = await got(`https://index.docker.io/v2/${repository}/tags/list`, {
headers: {
Authorization: `Bearer ${token}`
},
json: true,
});
for (let tag of allTags.body.tags) {
let digest = await got.head(`https://index.docker.io/v2/${repository}/manifests/${tag}`, {
headers: {
Authorization: `Bearer ${token}`,
Accept: `application/vnd.docker.distribution.manifest.v2+json`,
},
});
console.log(`${tag} ${digest.headers['docker-content-digest']}`);
}
})();
示例3: test
test('make requestt o https server with ca', async (t) => {
const {body} = await got(s.url, {
strictSSL: true,
ca: caRootCert,
headers: {host: 'sindresorhus.com'}
});
t.is(body, 'ok');
});
示例4: test
test('timeout option', async (t) => {
try {
await got(`${s.url}/404`, {timeout: 1, retries: 0});
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.code, 'ETIMEDOUT');
}
});
示例5: tmdbRequest
function tmdbRequest(resource: 'movie' | 'tv', id: string) {
return got(`https://api.themoviedb.org/3/${resource}/${id}`, {
query: {
api_key: process.env.TMDB_API_KEY
},
json: true
})
}
示例6: test
test('should have statusCode in err', async (t) => {
try {
await got(`${s.url}/non200-invalid`, {json: true});
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.statusCode, 500);
}
});
示例7: test
test('throws on endless redirect', async (t) => {
try {
await got(`${http.url}/endless`);
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.message, 'Redirected 10 times. Aborting.');
}
});
示例8: test
test('object in options.bodyt reated as querystring', async (t) => {
const {body} = await got(s.url, {
body: {
such: 'wow'
}
});
t.is(body, 'such=wow');
});
示例9: test
test('options.body error message', async (t) => {
try {
await got(s.url, {body: () => {}});
t.fail('Exception was not thrown');
} catch (err) {
t.regex(err.message, /options.body must be a ReadableStream, string, Buffer or plain Object/);
}
});