Secure and Robust Database Connectors with webMethods.io
Tags: database, webmethods, apimanagement, api
Published: 2023-06-09 11:14:25

---
title: Secure and Robust Database Connectors with webMethods.io
published: true
date: 2023-05-29 07:32:45 UTC
tags: database, webmethods, apimanagement, api
canonical_url: https://tech.forums.softwareag.com/t/secure-and-robust-database-connectors-with-webmethods-io/278997
---

 

**Connecting to a database is one of the most rudimentary tasks a developer might encounter. However, despite appearing as a simple bit of code, database connections can be a source of significant problems and potential security vulnerabilities.**

![01](https://global.discourse-cdn.com/techcommunity/original/3X/6/1/61cf87e45b3653c0925b3300194b4bcdc1a0d75f.jpeg)

New database connection strategies provide a secure, efficient, managed, and centralized method for handling database connections. [webMethods.io](http://webMethods.io) Integration, a service from Software AG, helps prevent the inclusion of sensitive security credentials in code, prevent connection errors, and reduce the attack surface available to potential attackers.

This article walks you through the pros and cons of traditional and modern database connection methods. You will also learn how to use Software AG to make worry-free connections to any database with a short hands-on tutorial.

## Understanding database connections

Typically, after creating a database, you want to connect it to a client application that reads the data, alters it, and sends new data to store. For a connection to be possible, a database server must provide the details that a client needs to initiate a connection. Some of those details include user authentication and authorization credentials, an endpoint, a port number, and a database name.

A client application’s request contains the database connection details needed to initiate a connection. The data sent between a client application and a database is encrypted to protect the connection from a man-in-the-middle attack.

### Traditional database connection issues

The traditional database connection method has inherent security risks and operational inefficiencies.

This method requires the client to handle the database connection, which means the sensitive connection details are included in the source code. The presence of such details in the source code increases the risk of a malicious attacker obtaining them. Alternatively, users might opt to save the credentials in an easily accessible file, which produces additional security vulnerabilities.

The traditional method requires opening a connection from an application and making direct requests to the database server. This process makes the database susceptible to malicious requests and attacks, such as denial of service (DoS) and SQL injection attacks.

### Data layer

A data layer holding all information management services ensures data is correctly entered, stored, and retrieved. It keeps data in a simple format easily accessible to client applications, reducing the latency associated with data delivery.

The webMethods data layer also ensures timely data delivery and decreased latency with data operations. Finally, it pushes data to its store uniformly, easing its management, storage, and retrieval.

Another feature of the webMethods data layer is the ability to distribute data simultaneously to different applications. The only requirement is to connect the data source and the consuming app.

### Worry-Free database connections with Software AG

Software AG’s [webMethods.io Integration](https://developer.softwareag.com/en/webmethods-io-integration.html) service is a robust integration platform as a service (iPaaS), providing the combined capabilities of application integration systems, API management tools, and B2B gateways.

It simplifies connecting to a database with predefined connectors and the ability to build custom connectors. To connect to a database, you simply select the database’s connector, enter the connection details, and save the associated account, which you can use to implement different types of integrations in a workflow.

This integration resolves the challenge of traditional database connections by securely storing encrypted database connections in easily accessible accounts. To integrate a connector into a flow, you simply select a connector and the account you want to use. You can also safely store sensitive connection details in the cloud, minimizing the possibility of an attack using stolen credentials.

With webMethods, you connect different components visually by selecting them, dragging them, and adding a connection arrow. The system handles the backend code, and you only need to select the data you want to pass.

Let’s take a look at the visual connection in action.

### Visual connection in action

In this section, you’ll create a simple API and connect it to Software AG using Node.js. Then, you’ll initiate and confirm connections to MySQL, Postgres, and MongoDB databases using Software AG’s visual connection method. The project uses Visual Studio Code running on Windows 10.

#### Prerequisites

To follow this section, you need the following:

- Node.js installed
- Access to a MongoDB database and [a valid connection string](https://www.mongodb.com/docs/guides/atlas/connection-string/)
- Access to a Postgres database
- Access to a MySQL database
- A Software AG [developer account](https://developer.softwareag.com/en/webmethods-io-integration.html) with access to [webMethods.io](http://webMethods.io) Integration

Finally, ensure the tables or collections you create for the databases store two string variables: `name` and `score`.

#### Creating a simple API

Start by creating a simple API in Node.js. Open a terminal, navigate to the folder you want to use for the project, and run this command:

`npm init -y`

Add [axios](https://www.npmjs.com/package/axios), a promise-based HTTP client for Node.js, by running the command below:

`npm i axios --save`

Create a file named server.js in the project’s root folder and add the code below to it.

```
var axios = require('axios');
var data = JSON.stringify({
  "name": String,
  "score": String
});

var config = {
  method: 'post',
  url: '<WORKFLOW LINK>',
  headers: {
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

#### Connect to Software AG

Now you connect to Software AG on [webMethods.io](http://webMethods.io) Integration.

Start by creating a new project and a new workflow inside it. Then, open the workflow and double-click the green play button in the workspace to add a trigger.

As you are creating an API, add a webhook trigger. Selecting the webhook option gives you a URL that the Node.js API uses to connect to Software AG.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/9/4/94e607a321cc14949f547ae1c4aed80aa7b9ccfb_2_650x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/9/4/94e607a321cc14949f547ae1c4aed80aa7b9ccfb.png "image")

Copy the URL and add it to the server.js file in your Node.js project.

The new server.js file looks like this:

```
var axios = require('axios');
var data = JSON.stringify({
  "name": "Patrick Jones",
  "score": "68"
});

var config = {
  method: 'POST',
  url: '<WORKFLOW WEBHOOK PAYLOAD URL>',
  headers: {
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

Now run the Node.js file to send the payload to the webhook on webMethods Integration. Open a terminal in the Node.js project’s root folder and run the command below:

`node server.js`

You should receive the following output:

`{"message":"Mock payload data set for your workflow. To execute the workflow, please use the live webhook URL <WORKFLOW URL>","code":153}`

Navigate back to the webhook on webMethods Integration and click **Fetch** to view the payload sent by the Node.js API.

Below is the received payload data:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/9/2/92d3ce5e0feca216e2197598a178b1cd60e84fc1_2_658x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/9/2/92d3ce5e0feca216e2197598a178b1cd60e84fc1.png "image")

This confirms your API is now connected. After the workflow is completed, you change the node.js code to use the actual webhook URL instead of the payload test one. You can then run the node.js code and see the workflow being executed live (if you enable the option to see this in the workflow settings).

To keep this sample project simple, save the webhook without any authentication.

Next, you’ll connect to the database and save the data sent by the API.

#### Connect to different databases

On the right sidebar, search for the **MySQL** connector. Fill in the details and save the account as shown below:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/a/c/ace60195e1c376f960426101c32f6792d51888ac_2_414x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/a/c/ace60195e1c376f960426101c32f6792d51888ac.png "image")

Fill in the database server details and click **Save** to save the connection account.

On the right sidebar, search for the **Database** connector. Name your connection account, and from the **Database** menu, select **Postgres**. Under **Driver Group** , select **Postgres JDBC**  **Driver**. Then, fill in the other fields with your Postgres database connection details and save the connection account.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/8/1/81dbf5597705785ed942a4de0cd720ce16779c40_2_690x406.png)](https://global.discourse-cdn.com/techcommunity/original/3X/8/1/81dbf5597705785ed942a4de0cd720ce16779c40.png "image")

On the right sidebar, search for the **MongoDB** connector. Select **MongoDB** and fill in the form with your MongoDB connection details. Finally, save the connection account.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/1/619cc3ea73331eddac566efd650d50c719f2aa58_2_552x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/1/619cc3ea73331eddac566efd650d50c719f2aa58.png "image")

#### Creating the data-saving workflow

Navigate to the workflow where you made the webhook and add the three databases as shown below.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/5/b/5bbc711a6282ce7ed0703af95f51c091c15c3503_2_690x377.png)](https://global.discourse-cdn.com/techcommunity/original/3X/5/b/5bbc711a6282ce7ed0703af95f51c091c15c3503.png "image")

After saving the workflow, play it to send the payload data to all three databases.

Here is the workflow execution log:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/f/c/fc8fc684ca914a9f190bddcb25d5c185f293938c_2_690x188.png)](https://global.discourse-cdn.com/techcommunity/original/3X/f/c/fc8fc684ca914a9f190bddcb25d5c185f293938c.png "image")

Below are the inputs passed to MySQL:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/0/204975189feb020bee1fe72ac11983f964d27aae_2_690x188.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/0/204975189feb020bee1fe72ac11983f964d27aae.png "image")

The next image shows the inputs passed to Postgres:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/8/a/8aacc9e6bccbf76b93e751bc979eb7412f7c1e7e_2_690x251.png)](https://global.discourse-cdn.com/techcommunity/original/3X/8/a/8aacc9e6bccbf76b93e751bc979eb7412f7c1e7e.png "image")

Finally, here are the inputs passed to MongoDB:

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/d/ddc7742fee60f36bd1b2a3d5dcc16519ab0158fe_2_682x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/d/ddc7742fee60f36bd1b2a3d5dcc16519ab0158fe.png "image")

Now that the three database connectors are working properly, we can test sending data to the databases from the Node.js application by running the application using the following:

`node server.js`

The image below shows how the workflow changes as the data received by the webhook are sent to the different databases.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/e/c/ec6a8481b803ddd39f0d0763dc32143accf9445b_2_690x378.jpeg)](https://global.discourse-cdn.com/techcommunity/original/3X/e/c/ec6a8481b803ddd39f0d0763dc32143accf9445b.jpeg "image")

That’s it. You have created an API connected to Software AG and made a connection to three databases.

## Conclusion

The traditional database connection method is prone to errors and increases the risk of hackers gaining access to your databases.

The new visual connection method using [webMethods.io](http://webMethods.io) Integration eliminates the problem of typo errors by saving database connections in reusable accounts. It also lowers security risks by providing an API layer for a database that you can use to offer business-focused data APIs instead of generic database APIs, which simplifies development for application developers. It also reduces the attack surface as the database is only accessible through the APIs, which offer more restricted interfaces and validation.

[Check out Software AG Cloud to learn more](https://www.softwareag.cloud/site/product/webmethods-api.html#/)

[Read full topic](https://tech.forums.softwareag.com/t/secure-and-robust-database-connectors-with-webmethods-io/278997)