Last active
December 6, 2019 23:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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