REST to SOAP

Examples of how to use Bi-direct to make REST API calls to a server that only supports SOAP requests.

Bi-Direct endpoint for REST to SOAP: https://tri-way.vercel.app/resttosoap

Just like a REST API call if you want to pass any data and the required data in the request body, you need to include a JSON object with the following keys:

  • Url: The endpoint URL of the SOAP API you want to use

  • Method: The HTTP method for the API call (POST, GET, PUT, DELETE, etc.)

  • Data (optional): The request body data for the POST or PUT request

Example of a POST request

Normally this is how a soap request looks like

Host: www.dataaccess.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>1234</ubiNum>
    </NumberToWords>
  </soap12:Body>
</soap12:Envelope>

Output for the above-given soap request will look something like this

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <NumberToWordsResponse xmlns="http://www.dataaccess.com/webservicesserver/">
      <NumberToWordsResult>one thousand two hundred and thirty four</NumberToWordsResult>
    </NumberToWordsResponse>
  </soap12:Body>
</soap12:Envelope>

Example of a POST request made using Bi-Direct

Headers

headers: {
    'Content-Type': 'application/json'
  }

Request Body (POST request)

Note

The input data for the SOAP request is specified in the "Data" property. The "NumberToWords" property specifies the name of the SOAP operation, and the ubiNum property specifies the input parameter. The "#" property specifies the value of the input parameter, which is unsignedLong. The "@" the property specifies the namespace declaration for the NumberToWords element.

{
  "Url": "https://www.dataaccess.com//webservicesserver/NumberConversion.wso?op=NumberToWords",
  "Method": "POST",
  "Data": {
    "NumberToWords": {
      "@": {
        "xmlns": "http://www.dataaccess.com/webservicesserver/"
      },
      "ubiNum": {
        "#": "1234"
      }
    }
  }
}
Generated output for the given POST request
{
  "soap:Envelope": {
    "$": {
      "xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/"
    },
    "soap:Body": [
      {
        "m:NumberToWordsResponse": [
          {
            "$": {
              "xmlns:m": "http://www.dataaccess.com/webservicesserver/"
            },
            "m:NumberToWordsResult": [
              "one thousand two hundred and thirty four "
            ]
          }
        ]
      }
    ]
  }
}
Javascript code (Axios)
let headersList = {
  "Content-Type": "application/json"
 }
 
 let bodyContent = JSON.stringify({
  "Url": "https://www.dataaccess.com//webservicesserver/NumberConversion.wso?op=NumberToWords",
  "Method": "POST",
  "Data": {
    "NumberToWords": {
      "@": {
        "xmlns": "http://www.dataaccess.com/webservicesserver/"
      },
      "ubiNum": {
        "#": "1234"
      }
    }
  }
});

async function makeRequest() { 
 let response = await fetch("https://tri-way.vercel.app/resttosoap", { 
   method: "POST",
   body: bodyContent,
   headers: headersList
 });
 
 let data = await response.text();
console.log(data);
}
 
makeRequest()

Last updated