Skip to content

Instantly share code, notes, and snippets.

@swarajgiri
Last active March 20, 2020 07:51
Show Gist options
  • Save swarajgiri/60b36af02b539a2cb3cc325eca4b9f64 to your computer and use it in GitHub Desktop.
Save swarajgiri/60b36af02b539a2cb3cc325eca4b9f64 to your computer and use it in GitHub Desktop.
Make a http call with axios
const axios = require('axios);
async function getFromAria( ){
try {
const ariaResponse = await axios({
url: '/downstreamUri',
// `method` is the request method to be used when making the request
method: 'get', // default
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL: 'https://downstreamUri-domain.com/api/',
httpsAgent: new https.Agent({
// pass your certs here
})
// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
// FormData or Stream
// You may modify the headers object.
transformRequest: [function (data, headers) {
// Do whatever you want to transform the data
return data;
}],
});
} catch (err) {
console.log('Error occured while hitting downstream url', err)
}
}
// call the above function
getFromAria()
.then(function (returnOfgetFromAria) => {
// happy path
})
.catch(function (err){
// something broke
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment