Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM SOAP package - client as singleton?

I'm using this npm package: https://www.npmjs.com/package/soap

I could not find an answer in the documentation, as I'm wondering if the best practice for SOAP client is to create a single client as startup and use for all requests (similar to database client), or create a new one per request.

like image 361
David Faizulaev Avatar asked Oct 24 '17 14:10

David Faizulaev


People also ask

Does node js support SOAP?

A SOAP client and server for node. js. This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.

What is a strong SOAP?

strong-soap provides a mock-up SOAP server capability to implement and test a web service. Here is an example of creating a SOAP server and sending a JSON response: var soap = require('strong-soap').

What is SOAP Nodejs?

SOAP is basically an XML based API that existed before the REST API existed. SOAP stands for Simple Object Access Protocol – it's a mostly legacy protocol that was designed for doing remote api requests in a language independent way.


1 Answers

It depends on your use case and application requirements.

After reading up on the code of the node-soap, the following happens when createClient() is called:

  • createClient(url, options, cb) internally creates a wsdl handler for the particular url in question (wsdl.open_wsdl())
  • the wsdl handler is cached with the url as key (unless options.disableCache is true)
  • createClient() calls back with Client() which wraps the wsdl handler

So, unless your url changes, it should be ok for you to use it as a singleton, since there's no need to run the setup code for wsdl yet again.

If your url changes (or if you aren't sure if it changes), use createClient() for each call. The wsdl setup will still be cached, so there's no overhead for you in this case (except for the first time the wsdl is created).

like image 60
ralphtheninja Avatar answered Oct 23 '22 23:10

ralphtheninja