在NodeJS-ExpressJS应用中找不到响应标题

时间:2019-12-12 16:53:58

标签: node.js express server http-headers response-headers

我已经使用node / express.js设置了一个简单的api请求来访问Feedly Dev Api:https://developer.feedly.com/。 Feedly Api带有两个响应标头-X-Ratelimit-CountX-Ratelimit-Reset。问题是我不知道如何访问。

这是我的express.js文件的相关部分:

app.get('/feedly', async (request, response) => {
  const apiUrl =
    'https://cloud.feedly.com/v3/streams/contents?streamId=user/[USER_ID]/category/global.all'

  const fetchResponse = await fetch(apiUrl, {
    headers: {
      Authorization: `Bearer ${process.env.FEEDLY_ACCESS_TOKEN}`
    }
  })
  const json = await fetchResponse.json()
  response.json(json)
  response.end()
})

要查看X-Ratelimit-Count和X-Ratelimit-Reset响应标头,我该怎么做?

谢谢。

1 个答案:

答案 0 :(得分:1)

获取API:Headers

(async() => {
  const fetchResponse = await fetch("https://httpbin.org/anything");
  
  console.log(fetchResponse.headers.get('X-Ratelimit-Count'))
  console.log(fetchResponse.headers.get('X-Ratelimit-Reset'))
  
  fetchResponse.headers.forEach((v, k) => console.log(`${k}: ${v}`));
})();