Version 1
[yaffs-website] / vendor / jcalderonzumba / gastonjs / examples / nodejs / main.js
1 "use strict";
2 var http = require("http");
3
4 var visitCommand = JSON.stringify({name: 'visit', args: ['http://www.google.es']});
5 var renderCommand = JSON.stringify({name: 'render', args: ['/Users/juan/Downloads/page_image.png', true, null]});
6
7 var postOptions = {
8   host: '127.0.0.1',
9   port : 8510,
10   path: '/api/v1',
11   method: 'POST',
12   headers: {
13     'Content-type': 'application/json',
14     'Content-Length': visitCommand.length
15   }
16 };
17
18 var postRequest = http.request(postOptions, function(res){
19   res.setEncoding('utf8');
20   res.on('data', function(chunk){
21     console.log(chunk);
22   });
23 });
24
25 postRequest.write(visitCommand);
26 postRequest.end();
27
28 postOptions.headers['Content-Length']=renderCommand.length;
29 postRequest = http.request(postOptions, function(res){
30   res.setEncoding('utf8');
31   res.on('data', function(chunk){
32     console.log(chunk);
33   });
34 });
35
36 postRequest.write(renderCommand);
37 postRequest.end();