Howto Debug (Inspect) Request Headers sent by Netlify Function to API?

I’ve searched all over for this information and can’t find it.

For a Netlify Function that uses node-fetch to GET data from a third party API endpoint, how can one debug (inspect, see, view) the Request headers AS SENT by Netlify to the API from the function?

I’m trying to set some headers the API wants and I don’t think they are being set correctly, and there is no way to tell since I can’t inspect the request. I could mock the third-party API using Postman, but I’d prefer to know if there is a direct Netlify way.

Note: the function does not require a build step, it’s just a simple zip-it-and-ship-it using Netlify Dev. Example code:

const fetch = require('node-fetch');

const { API_KEY, API_BASE } = process.env;

exports.handler = async function(event, context) {

  const { endpoint } = event.queryStringParameters;
  const url = `${API_BASE}${endpoint}?access_key=${API_KEY}`;

  try {
    const res = await fetch(url, {
      headers: {
        'accept': 'application/json',
        'if-modified-since':' foo',
        'if-none-match': 'bar',
      }
    });

..snipp...rest of code

Thank you

I’d suggest making a request to a service like requestbin.com if you can’t get that info out of your own API (which is totally understandable if you don’t host it) - that’s the best source of truth, what was actually observed on the wire.

Thank you for your response, much appreciated. That’s a workaround, for now. Although that’s what I was already doing via mocking with Postman. Yes, it’s a third-party API

1 Like