Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

node.js - Replacing depreciated request npm module with got

I am trying to replace requests using depreciated request npm module with got. When I hardcode my api key it works fine.

    const custom = got.extend({
        prefixUrl: url,
        responseType: 'json',
        headers: { "X-API-Key": "<myKey>" }
    });

    const response = await custom('<my url>' + limit + '&offset=' + offset + '&format=json');

When I try to pass an API key that I retrieve from AWS Secrets Manager it is undefined.

    const custom = got.extend({
        prefixUrl: url,
        responseType: 'json',
        headers: apiKey
    });

   const response = await custom('<my url>' + limit + '&offset=' + offset + '&format=json');

I was able to do this without a problem with the request module.

    const requestInfo = {
        method: 'GET',
        uri: url
        timeout: 300000,
        encoding: null,
        resolveWithFullResponse: true,
        headers: apiKey,
        json: true
    };

    const response = await request(requestInfo);

I am sure it is something I am not understanding about the got npm module, but I haven't been able to find an answer in the documentation. Does anyone know why I can't pass the value using got?

question from:https://stackoverflow.com/questions/66056554/replacing-depreciated-request-npm-module-with-got

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...