Making API Request With Authorization Header

Image for post
Image for post
fetch('url/api endpoint', { headers: {" Authorization":"api key here" }}) .then(res)=>res.json() .then(data=>{ console.log(data) } .catch({ console.log(error) })
// 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); } }

Web developer, 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