typescript api request header 1

typescript api request header

const headerDict = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Access-Control-Allow-Headers': 'Content-Type',
}

const requestOptions = {                                                                                                                                                                                 
  headers: new Headers(headerDict), 
};

return this.http.get(this.heroesUrl, requestOptions)

Here is what the above code is Doing:
1. We’re creating a headerDict object that contains the headers we want to send with our request.
2. We’re creating a requestOptions object that contains the headers we want to send with our request.
3. We’re sending a GET request to the heroesUrl endpoint with the requestOptions object as the second argument.

Similar Posts