make a http request with a custom header in typescript

index.ts
import axios, { AxiosRequestConfig } from 'axios';

const config: AxiosRequestConfig = {
  headers: { 'Custom-Header': 'Some value' },
};

axios.get('https://example.com/api/data', config)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });
298 chars
14 lines

The header field in the config object can be used to specify any custom headers that need to be sent with the request. In this case, the Custom-Header with a value of Some value is being sent along with the GET request to https://example.com/api/data.

The axios library is being used here for making the HTTP request. It is a popular client for making HTTP requests in JavaScript/TypeScript.

gistlibby LogSnag