Created
June 15, 2017 00:44
-
-
Save jkriss/d939a54b61eb88d94bd1abf6c6ea8049 to your computer and use it in GitHub Desktop.
CTA Aggregator api example
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<title>CTA Aggregator API example</title> | |
</head> | |
<body> | |
<pre id="events"></pre> | |
<pre id="advocacy_campaigns"></pre> | |
<script type="text/javascript"> | |
// set this to the actual api endpoint | |
var baseUrl = 'http://localhost:3000/v1' | |
// this works in modern browsers, | |
// will need fetch and promise polyfills in older browsers | |
function get(path) { | |
return fetch(baseUrl+path) | |
.then(function(response) { | |
return response.json() | |
}) | |
.then(function(response) { | |
return response.data.map(function(d) { return d.attributes }) | |
}) | |
} | |
get('/events?include=location').then(function(events) { | |
document.getElementById('events').innerText = JSON.stringify(events, null, 2) | |
}) | |
get('/advocacy_campaigns').then(function(campaigns) { | |
document.getElementById('advocacy_campaigns').innerText = JSON.stringify(campaigns, null, 2) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment