Skip to content

Instantly share code, notes, and snippets.

@tsundara
Last active December 6, 2019 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsundara/f4c4657572d5bd72cb8d4c73436eb583 to your computer and use it in GitHub Desktop.
Save tsundara/f4c4657572d5bd72cb8d4c73436eb583 to your computer and use it in GitHub Desktop.
Self contained html file in which Axios http client calls an external REST API , loops through the array data and displays it in a table
<!DOCTYPE html>
<html lang="en">
<head>
<title>Axios Example</title>
</head>
<body>
</body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
axios({
method: 'get',
url: 'https://indian-cities-api-nocbegfhqg.now.sh/cities',
responseType: 'json'
})
.then(function (r){
document.write('<table border="1" cellpadding="0" cellspacing="0" width="200px" style="border-collapse:collapse;">')
for(i=0; i<r.data.length; i++){
document.write("<tr><td>" + r.data[i].City + "</td><td>" + r.data[i].State + "</td><td>" + r.data[i].District + "</td></tr>" );
}
document.write("</table>")
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment