Making API Request With Authorization Header

  • Basic npm/npx/yarn knowledge.
fetch('url/api endpoint', { headers: {" Authorization":"api key here" }}) .then(res)=>res.json() .then(data=>{ console.log(data) } .catch({ console.log(error) })
  • Make http requests from node.js
  • Supports the Promise API
  • Intercept request and response
  • Transform request and response data
  • Cancel requests
  • Automatic transforms for JSON data
  • Client side support for protecting against XSRF
// Add the async keyword to your outer function/method. async function getRequest() { try { const response = await axios.get('url/api endpoint',{ headers:{"Authorization":"api-key goes here"}}); console.log(response); } catch (error) { console.error(error); } }
  • How to include header in our requests
  • How to handle and catch errors
  • How to make asynchronous request using async await

Web developer, Life Café https://medium.com/life-cafe , Curious Soul, twitter at @amjohnphilip,

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store