Skip to content

Instantly share code, notes, and snippets.

@robb1e
Created January 27, 2011 12:54
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 robb1e/798467 to your computer and use it in GitHub Desktop.
Save robb1e/798467 to your computer and use it in GitHub Desktop.
Node.JS connection to Guardian Content API
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}
});
});
});
<h1><%= name %> by guardian.co.uk</h1>
<%- partial('item.ejs', res.response.results) %>
<% 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