Version 1
[yaffs-website] / vendor / jcalderonzumba / gastonjs / examples / nodejs / main.js
diff --git a/vendor/jcalderonzumba/gastonjs/examples/nodejs/main.js b/vendor/jcalderonzumba/gastonjs/examples/nodejs/main.js
new file mode 100644 (file)
index 0000000..1ba7e56
--- /dev/null
@@ -0,0 +1,37 @@
+"use strict";
+var http = require("http");
+
+var visitCommand = JSON.stringify({name: 'visit', args: ['http://www.google.es']});
+var renderCommand = JSON.stringify({name: 'render', args: ['/Users/juan/Downloads/page_image.png', true, null]});
+
+var postOptions = {
+  host: '127.0.0.1',
+  port : 8510,
+  path: '/api/v1',
+  method: 'POST',
+  headers: {
+    'Content-type': 'application/json',
+    'Content-Length': visitCommand.length
+  }
+};
+
+var postRequest = http.request(postOptions, function(res){
+  res.setEncoding('utf8');
+  res.on('data', function(chunk){
+    console.log(chunk);
+  });
+});
+
+postRequest.write(visitCommand);
+postRequest.end();
+
+postOptions.headers['Content-Length']=renderCommand.length;
+postRequest = http.request(postOptions, function(res){
+  res.setEncoding('utf8');
+  res.on('data', function(chunk){
+    console.log(chunk);
+  });
+});
+
+postRequest.write(renderCommand);
+postRequest.end();