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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…