Last active
August 29, 2015 14:06
-
-
Save dmode/d8dc18f2e235884b04b0 to your computer and use it in GitHub Desktop.
Node.js modules to retreive data from the TNT Weight and Dimension webservice. Module is using http://visionmedia.github.io/superagent/ node module.
This file contains hidden or 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 request = require('superagent'); | |
router.get('/listcountries', function(req, res) { | |
//load settings | |
var url = 'http://tsp-weightanddims.azurewebsites.net/api/v1/wad/country/list'; | |
var apiKey = '123456789'; | |
// call the service | |
request.get(url) | |
.set('apikey', apiKey) | |
.set('Content-Type', 'application/json') | |
.end(function(err, response) { | |
if(err) return res.status(500).send(err.message); | |
if(!response.ok) return res.send(response.statusCode + ' ' + response.text); | |
res.send(JSON.parse(response.text)); | |
}); | |
}); | |
This file contains hidden or 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 request = require('superagent'); | |
/* GET wad origin,destination country selection listing. */ | |
router.get('/getbyoriginanddestination', function(req, res) { | |
//load the settings | |
var url = 'http://tsp-weightanddims.azurewebsites.net/api/v1/wad/getByOriginAndDestination?origin=CH&destination=DE'; | |
var apiKey = '123456789'; | |
var origin = req.query.origin; | |
var destination = req.query.destination; | |
//call service | |
request.get(url) | |
.set('apikey', apiKey) | |
.set('Content-Type', 'application/json') | |
.query({ origin: origin }) | |
.query({ destination: destination }) | |
.end(function(err,response){ | |
if(err) return res.status(500).send(err.message); | |
if(!response.ok) return res.send(response.statusCode + ' ' + response.text); | |
res.send(JSON.parse(response.text)); | |
}); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment