Created
March 21, 2015 16:50
-
-
Save sharno/e18f2857aea9018c8f38 to your computer and use it in GitHub Desktop.
trial
This file contains 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 express = require('express'); | |
var request = require('request'); | |
var async = require('async'); | |
var querystring = require('querystring'); | |
var app = express() | |
var myUrl = "http://jes.iti.gov.eg/CitySDK/categories?List=poi" | |
var auth = "http://jes.iti.gov.eg/CitySDK/auth?username=admin&password=defaultCitySDKPassword" | |
app.post('/', function (req, res) { | |
// res.send('Hello World!'); | |
// async.series(request({url: url, method: 'GET'}, callback)); | |
request({url: myUrl, method: 'GET', json: true}, function(error, response, body) { | |
// res.send(data); | |
// console.log(body); | |
if (!error && response.statusCode == 200) { | |
console.log(body); | |
res.send(body) | |
} | |
}); | |
}) | |
app.get('/', function (req, res) { | |
var data = {"list":"poi", "category" : { "label" : [ { "lang" : "pt-PT", | |
"term" : "primary", | |
"value" : "First Category" | |
}, | |
{ "lang" : "ar-EG", | |
"term" : "primary", | |
"value" : "test" | |
} | |
], | |
"lang" : "pt-PT", | |
"term" : "category", | |
"value" : "test" | |
} | |
} | |
request({url: auth, method: 'GET', json: true}, function(error, response, body) { | |
// res.send(data); | |
// console.log(body); | |
if (!error && response.statusCode == 200) { | |
console.log(body); | |
} | |
}); | |
request.put({url: myUrl, body: (data), json: true}, function(error, response, body) { | |
// res.send(JSON.stringify(data)); | |
res.send(response); | |
if (!error && response.statusCode == 200) { | |
console.log(body); | |
res.send(JSON.stringify(data)); | |
} | |
}); | |
var options = { | |
host: 'http://jes.iti.gov.eg', | |
path: '/CitySDK/categories?List=poi', | |
method: 'PUT' | |
}; | |
var req = http.request(options, function(res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
// write data to request body | |
req.write('data\n'); | |
req.write('data\n'); | |
req.end(); | |
// console.log(querystring.stringify(data)); | |
// var data = '{"list" : "poi","category": { "label": [{"lang": "pt-PT", "term": "primary","value": "My Second cat" },{"lang": "ar-EG", "term": "primary", "value": "test"} ],"lang": "pt-PT", "term": "category", "value": "teste"} }' | |
// var data2 = '{"List": "poi", "category": { "label": [ { "lang": "pt-PT", "term": "primary", "value": "First Category" },{ "lang": "ar-EG", "term": "primary", "value": "test" } ],"lang": "pt-PT", "term": "category", "value": "test" }}' | |
}) | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('CitySDK app listening at http://%s:%s', host, port); | |
}) | |
// app.use(express.static('public')); | |
// accept PUT request at /user | |
app.put('/user', function (req, res) { | |
// res.send('Got a PUT request at /user'); | |
request({ url: url, method: 'PUT', | |
json: {"List": "poi", | |
"category": { "label": [ | |
{ | |
"lang": "pt-PT", "term": "primary", | |
"value": "First Category" }, | |
{ | |
"lang": "ar-EG", "term": "primary", "value": "EXPRESS" | |
} ], | |
"lang": "pt-PT", "term": "category", "value": "EXPRESS" | |
}}} | |
, function(data){ | |
}); | |
console.log("sent"); | |
}); | |
// accept DELETE request at /user | |
app.delete('/user', function (req, res) { | |
res.send('Got a DELETE request at /user'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment