Add a Datasource
We will add a Datasource to the LB4 application using the CLI. This step will not only create two files under the src/datasources, but also will install the necessary connector and its dependencies for us. Let’s run the following command inside our application directory.
lb4 datasource calculator
Select a Connector type
We specified calculator as the name for our Datasource. Now CLI is asking us to select a connector type. Let’s choose the SOAP webservices (supported by StrongLoop) connector from the list as shown below:
? Select the connector for calculator:
Oracle (supported by StrongLoop)
Microsoft SQL (supported by StrongLoop)
REST services (supported by StrongLoop)
❯ SOAP webservices (supported by StrongLoop)
Couchbase (provided by community)
Neo4j (provided by community)
Kafka (provided by community)
(Move up and down to reveal more choices)
Specify the SOAP web service endpoint
Now we must tell CLI about the full URL path for our web service. In this
case, let’s type http://lb4ws.eycgrupo.com/calculator
for the URL and
http://lb4ws.eycgrupo.com/calculator/?wsdl
for the WSDL path.
? Select the connector for calculator: SOAP webservices (supported by StrongLoop)
? URL to the SOAP web service endpoint: http://lb4ws.eycgrupo.com/calculator
? HTTP URL or local file system path to the WSDL file: http://lb4ws.eycgrupo.com/calculator/?wsdl
Enabling expose REST API operations
Following the URL endpoints, we need to tell CLI that we are going to expose the methods available in the SOAP web service as REST end points, type Y and leave blank the Maps WSDL binding operations to Node.js methods for now, as we will add them manually in the Datasource configuration file.
? Expose operations as REST APIs: Yes
? Maps WSDL binding operations to Node.js methods:
You will see the following message in the screen. Note that CLI created a JSON configuration file and a .ts file with the Datasource name and added an entry inside the index.ts file.
create src/datasources/calculator.datasource.json
create src/datasources/calculator.datasource.ts
update src/datasources/index.ts
Datasource calculator was created in src/datasources/
Binding WSDL operations to Node.js methods
The SOAP web service is exposing 4 operations, all of them share the same SOAP port, which in this case is CalculatorSoap and the service Calculator. The operations are:
- Multiply
- Add
- Subtract
- Divide
We need to configure in the Datasource JSON file, the corresponding Node.js methods for these remote SOAP operations. For simplicity, we will name the Node.js methods the same as their SOAP operation counterparts.
For example, having the following property, we are configuring the SOAP operator Multiply that is reached in the port CalculatorSoap and Calculator service to bind the Node.js method Multiply.
"operations": {
"Multiply": {
"service": "Calculator",
"port": "CalculatorSoap",
"operation": "Multiply"
}
}
Edit the file src/datasources/calculator.datasource.json
and add the following
configuration after the remoteEnabled: true,
property as follows:
src/datasources/calculator.datasource.json
"operations": {
"Multiply": {
"service": "Calculator",
"port": "CalculatorSoap",
"operation": "Multiply"
},
"Add": {
"service": "Calculator",
"port": "CalculatorSoap",
"operation": "Add"
},
"Subtract": {
"service": "Calculator",
"port": "CalculatorSoap",
"operation": "Subtract"
},
"Divide": {
"service": "Calculator",
"port": "CalculatorSoap",
"operation": "Divide"
}
}
Navigation
Previous step: Create your app scaffolding
Next step: Add a Service