Skip to content


Subversion checkout URL

You can clone with
Download ZIP
44 lines (38 sloc) 1.5 KB
* Usage: node-streamline googleClient searchString
* Demonstrates the streamline http client wrapper
"use strict";
// require the ez-streams package (you must install it with npm install ez-streams)
var ez = require('ez-streams');
function google(str, _) {
// Create the request.
// The options are the same as for node's http.request call.
// But the call also accepts a simple URL for the GET case
// But ez.devices.http.client does not take any callback parameter.
// Instead, the callback is passed to the response(_) method (a few lines below).
var req = ez.devices.http.client({
url: '' + str,
proxy: process.env.http_proxy
// In the case of a POST request, this is where you would send
// the body with req.write calls.
// End the request and get a response object (asynchronously)
var resp = req.end().response(_);
// Check the status, read the whole body (asynchronously) and parse it.
return JSON.parse(resp.checkStatus(200).readAll(_));
try {
// get the search string from the command line, defaulting to "node.js"
var str = process.argv.length > 2 ? process.argv[2] : "node.js";
// call google to get search results
var result = google(str, _);
// format the result and print it to console
var formatted = {
return entry.url + '\n\t' + entry.titleNoFormatting;
} catch (ex) {
Jump to Line
Something went wrong with that request. Please try again.