Skip to content

Instantly share code, notes, and snippets.

@jkriss
Created June 15, 2017 00:44
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 jkriss/d939a54b61eb88d94bd1abf6c6ea8049 to your computer and use it in GitHub Desktop.
Save jkriss/d939a54b61eb88d94bd1abf6c6ea8049 to your computer and use it in GitHub Desktop.
CTA Aggregator api example
<!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