/easy-soap-request

Small Node.js library to make SOAP requests easier

Primary LanguageJavaScriptMIT LicenseMIT

easy-soap-request

Travis npm version npm downloads Dependencies status Dev Dependencies status Known Vulnerabilities Coveralls Status

NPM

A small library to make SOAP requests easier via Node.js or in the browser

Installation

npm install easy-soap-request

Requirements

  • Node.js >=7.6.0 (async/await support)

Usage

Node.js

const soapRequest = require('easy-soap-request');
const fs = require('fs');

// example data
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const headers = {
  'user-agent': 'sampleTest',
  'Content-Type': 'text/xml;charset=UTF-8',
  'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};
const xml = fs.readFileSync('test/zipCodeEnvelope.xml', 'utf-8');

// usage of module
(async () => {
  const { response } = await soapRequest(url, headers, xml, 1000); // Optional timeout parameter(milliseconds)
  const { headers, body, statusCode } = response;
  console.log(headers);
  console.log(body);
  console.log(statusCode);
})();

Browser

Note: CORS policies apply

<html>
<script src="https://cdn.jsdelivr.net/npm/easy-soap-request@2.3.5/dist/easy-soap-request.js"></script>
<script>
    const url = 'https://my-soap-server';
    const headers = {
        'Content-Type': 'text/xml;charset=UTF-8',
        SOAPAction: 'https://my-soap-action/something',
    };
    const xml = `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                 <soapenv:Header/>
                 <soapenv:Body>Some Data</soapenv:Body>
                 </soapenv:Envelope>`;
    async function makeRequest() {
        const { response } = await soapRequest(url, headers, xml, 1000); // Optional timeout parameter(milliseconds)
        const { headers, body, statusCode } = response;
        console.log(headers);
        console.log(body);
        console.log(statusCode);
        document.body.innerHTML = body;
    };
    makeRequest();
</script>
<body></body>
</html>

Tests