Created
January 27, 2011 12:54
-
-
Save robb1e/798467 to your computer and use it in GitHub Desktop.
Node.JS connection to Guardian Content API
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
var connection = http.createClient(80, 'content.guardianapis.com'); | |
var request = connection.request('GET', q.uri, {'host':'content.guardianapis.com'}); | |
request.end(); | |
request.on('response', function(response){ | |
var apiData = ""; | |
response.setEncoding('utf8'); | |
response.on('data', function(chunk){ | |
apiData += chunk; | |
}); | |
response.on('end', function(){ | |
res.render('content.ejs', { | |
locals:{res:JSON.parse(apiData), name:q.name} | |
}); | |
}); | |
}); |
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
<h1><%= name %> by guardian.co.uk</h1> | |
<%- partial('item.ejs', res.response.results) %> |
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
<% if (item.fields !== undefined && item.fields.body !== '<!-- Redistribution rights for this field are unavailable -->') {%> | |
<h1><%= item.webTitle %></h1> | |
<%- item.fields.body %> | |
<% } %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment