Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Last active March 7, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cianclarke/de3418e7229c3b6b2cce to your computer and use it in GitHub Desktop.
Save cianclarke/de3418e7229c3b6b2cce to your computer and use it in GitHub Desktop.
Barcode Cloud finished app

Barcode Lookup

This service looks up a barcode by UPC id. It connects with a SOAP service, takes a mixed SOAP and CSV response, and returns JSON back to the client, more effectively mobilising the service.

Group Hello World API

hello [/hello]

'Hello world' endpoint.

hello [POST]

'Hello world' endpoint.

  • Request (application/json)

    • Body { "barcode": "9780201896831" }
  • Response 200 (application/json)

    • Body { "msg": "Hello world" }
var csv = require('csv');
var soap = require('soap');
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
function helloRoute() {
var hello = new express.Router();
hello.use(cors());
hello.use(bodyParser());
hello.all('/', function(req, res) {
var barcode = req.query.barcode || req.body.barcode;
var wsdlUrl = 'http://www.searchupc.com/service/UPCSearch.asmx?wsdl';
soap.createClient(wsdlUrl, function(err, soapClient){
// we now have a soapClient - we also need to make sure there's no `err` here.
if (err){
return res.status(500).json(err);
}
soapClient.GetProduct({
upc : barcode,
accesstoken : '924646BB-A268-4007-9D87-2CE3084B47BC'
}, function(err, result){
if (err){
return res.status(500).json(err);
}
// now we have the response, but the webservice returns it as a CSV string. Let's use the parser
var responseAsCsv = result.GetProductResult;
csv.parse(responseAsCsv, {columns : true}, function(err, parsedResponse){
if (err) {
return res.status(500).json(err);
}
// finally, we're ready to return this back to the client.
return res.json(parsedResponse);
});
});
});
});
return hello;
}
module.exports = helloRoute;
{
"name": "fh-app",
"version": "0.2.0",
"dependencies": {
"body-parser": "~1.0.2",
"cors": "~2.2.0",
"express": "~4.0.0",
"fh-mbaas-api": "5.5.4",
"request": "~2.40.0",
"csv": "^0.4.2",
"soap": "^0.8.0"
},
"devDependencies": {
"grunt-concurrent": "latest",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-watch": "latest",
"grunt-env": "~0.4.1",
"grunt-node-inspector": "~0.1.5",
"grunt-nodemon": "0.2.0",
"grunt-open": "~0.2.3",
"grunt-plato": "~1.0.0",
"grunt-shell": "^0.7.0",
"istanbul": "0.2.7",
"load-grunt-tasks": "^0.4.0",
"mocha": "^2.1.0",
"proxyquire": "0.5.3",
"should": "2.1.1",
"sinon": "^1.17.2",
"supertest": "0.8.2",
"time-grunt": "^0.3.2"
},
"main": "application.js",
"scripts": {
"test": "grunt unit",
"debug": "grunt serve",
"start": "node application.js"
},
"license": "mit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment