/  Technology   /  Using the Fetch API with API key header in JavaScript
fetch

Using the Fetch API with API key header in JavaScript

 

The Headers interface of the javascript Fetch API allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing headers from the list of the API request’s headers.

A Headers object(name, value) has an associated API header list. It is initially empty which consists of zero or more name,value pairs. We can add to this using methods like append(). In all methods of this javascript interface, header names are matched by case-insensitive byte sequence in javascript.

let myHeaders = new Headers({
  'Content-Type': 'text/xml'
});
// or, using an array of arrays:
myHeaders = new Headers([
  ['Content-Type', 'text/xml']
]);
myHeaders.get('Content-Type') // should return 'text/xml'

Leave a comment