-
-
Save edtshuma/cf972dd91807a05268a8b848cd37fdb6 to your computer and use it in GitHub Desktop.
How to a JSON API Wrapper for SOAP
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
const express = require('express'); | |
const https = require('https'); | |
const fs = require('fs'); | |
const cors = require('cors'); | |
const rpn = require('request-promise-native'); | |
const bodyParser = require('body-parser'); | |
/* eslint-disable comma-dangle,arrow-parens,max-len,no-console */ | |
const app = express(); | |
app.use(cors()); | |
app.set('port', 2323); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/check-age', (req, res) => { | |
const { | |
firstName, | |
lastName, | |
year, | |
month, | |
day, | |
minAge, | |
stateCode, | |
zip | |
} = req.body; | |
const xmlReqBody = ` | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.identityproofing.idm.risk.someurl.com/" xmlns:ns="http://ns.someurl.com/identity-proofing/1.0" xmlns:ns1="http://ns.someurl.com/survey/1.0"> | |
<soapenv:Header> | |
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> | |
<wsse:UsernameToken wsu:Id="UsernameToken-49" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> | |
<wsse:Username>someUserName</wsse:Username> | |
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somePassword</wsse:Password> | |
</wsse:UsernameToken> | |
</wsse:Security> | |
</soapenv:Header> | |
<soapenv:Body> | |
<ws:invokeIdentityService> | |
<identityProofingRequest ns:customerReference="TESTING" ns:locale="en_US" ns:transactionID="${new Date().toString()}" ns:version="2" xmlns="http://ns.someurl.com/identity-proofing/1.0" xmlns:ns2="http://ns.someurl.com/identity-proofing/1.0"> | |
<ns:workFlow>WorkFlow</ns:workFlow> | |
<ns:inputSubject> | |
<ns:person> | |
<ns:name> | |
<ns:first>${firstName}</ns:first> | |
<ns:last>${lastName}</ns:last> | |
</ns:name> | |
<ns:dateOfBirth> | |
<ns:Year>${year}</ns:Year> | |
<ns:Month>${month}</ns:Month> | |
<ns:Day>${day}</ns:Day> | |
</ns:dateOfBirth> | |
<ns:address ns:addressPurpose="PRIMARY_RESIDENCE"> | |
<ns:stateCode>${stateCode}</ns:stateCode> | |
<ns:zip5>${zip}</ns:zip5> | |
</ns:address> | |
</ns:person> | |
</ns:inputSubject> | |
</identityProofingRequest> | |
</ws:invokeIdentityService> | |
</soapenv:Body> | |
</soapenv:Envelope>`; | |
const options = { | |
method: 'POST', | |
uri: 'https://identitymanagement.someurl.com/identity-proofing/services/identityProofingServiceWS/v2', | |
body: xmlReqBody | |
}; | |
rpn(options) | |
.then(response => { | |
// do something with the response, then return it | |
res.json(response); | |
}) | |
.catch(err => { | |
console.log(err); | |
}); | |
}); | |
// Make sure the connection to the node server is encrypted | |
const sslOptions = { | |
key: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/privkey.pem'), | |
cert: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/fullchain.pem'), | |
ca: fs.readFileSync('/etc/letsencrypt/live/nodesrvr.com/chain.pem') | |
}; | |
// startup the https server | |
https.createServer(sslOptions, app).listen(app.get('port'), () => { | |
console.log(`Age checker listening on port ${app.get('port')}.`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment