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


TypeScript got類代碼示例

本文整理匯總了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, '');
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:7,代碼來源:headers.ts

示例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']}`);
  }

})();
開發者ID:OddenCreative,項目名稱:versionpress,代碼行數:27,代碼來源:get-dockerhub-digests.ts

示例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');
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:https.ts

示例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');
    }
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:http.ts

示例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
  })
}
開發者ID:xavdid,項目名稱:kerfuffle,代碼行數:8,代碼來源:tmdb.ts

示例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);
    }
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:json.ts

示例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.');
    }
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:redirects.ts

示例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');
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:post.ts

示例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/);
    }
});
開發者ID:cyounkins,項目名稱:typed-got,代碼行數:8,代碼來源:error.ts


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