How to use the API Builder MBS Connector

API Builder and MBS Connector
API Builder and MBS Connector

So you have an idea for a mobile or web app but you need somewhere to store your data and you also need REST APIs to access the data. Axway’s API Builder can create APIs and also has database connectors for MySQL, Oracle, MongoDB and MS SQL. But what if you don’t have data in one of these databases and you just want to spin quickly up a database and not deal with the infrastructure. Axway’s MBS can help. When coupled with API Builder, it provides a powerful database as a service with complete CRUD (create, read, update and delete) REST APIs.

The Axway Mobile Backend Services (MBS) connector is a plugin for API Builder that can connect to an MBS instance on the Axway platform that you can use to store your Model data. The Models can expose APIs directly, be used programmatically or can be used within the flow editor to interact with your MBS instance. In this blog post, we’ll describe how to use the MBS connector in an API Builder project.

The basic steps are as follows:

  • Use the Axway Platform Dashboard to create an MBS app and get the app key
  • Create a user in the MBS app
  • Create an API Builder app
  • Install and configure the MBS Connector
  • Launch your API Builder app
  • Go to the API Builder console and start creating models/apis for your app

Create an MBS App

Log in to the platform at platform.axway.com and select the Dashboard from the list of tiles. Click on the plus sign at the top and create a new MBS data source as shown in the screenshots below.

Axway Platform
Dashboard
Create MBS Datasource
Name the Datasource
MBS Datasource Details

Note that my MBS application is called LBMyMBS. It is also worth noting that there are two instances of the MBS created. One for dev and one for prod.

Click on the Configuration tab and click on Show to see your App Key. We’ll need that when we configure the API Builder MBS connector.

Create a User in the MBS App

In order to access the MBS data we’ll need an MBS user.

Click on the Manage Data tab:

Manage Data Tab

Click on Users:

User Object

Click on the Add User button and enter a username, email address and password for this user. You will need the username and password later.

Enter user credentials

Click on Save.

Create an API Builder App

If you don’t already have an API Builder project, then follow this guide to create one.

Install and configure the MBS Connector

Follow this guide to install the MBS connector in your API Builder project folder.

After installation, you’ll need to configure the connector by editing the configuration file, mbs.default.js, in the /conf folder. The contents of the configuration file are shown below:

module.exports = {
    connectors: {
        mbs: {
            connector: '@axway/api-builder-plugin-dc-mbs',
            key: process.env.MBS_KEY, // Your MBS App Key
            username: process.env.MBS_USERNAME, // MBS user
            password: process.env.MBS_PASSWORD // MBS password
        }
    }
};

We can either hard code the MBS key, username and password in the MBS connector configuration file or set them as environment variables when we launch the API Builder project.

Launch Your API Builder App

We’ll set the MBS key, username and password as environment variables when we launch our API Builder project as follows:

MBS_KEY=your_MBS_key MBS_USERNAME=your_MBS_username MBS_PASSWORD=your_MBS_userpassword npm start

Go to the API Builder Console and Start Creating Models/APIs for your App

Once your API Builder project is running, you can go to the API Builder console at http://localhost:8080/console.

API Builder Console

Click on the Models tab and click on the add model button. Give your model a name (e.g. employee) and select mbs in the connector field and add any comments.

Create new model

Click Next.

Employee Model Page

Now we can add a few fields to our model.

Click on the add field button and add required string fields for first name and last name:

Add Fields

Click Next and then Save. You will see that the API Builder app restarts and then you should see your model:

Models Page

Here comes the best part. Click on API Doc & Test to see the CRUD APIs for your new model:

Employee APIs

You can see below how I am creating an employee and then retrieving all employees:

Create new employee
Retrieve all employees

Now you can continue to create models and/or edit your models. When you are done, you can publish your API Builder project to any Docker framework or to the Axway ARS (AMPLIFY Runtime Services) as described here.

Summary

In this blog post, we looked at how API Builder, MBS and the API Builder MBS connector can be used to rapidly create a Database as a Service complete with full CRUD APIs. This helps you innovate more quickly since you can focus your time on your application and less time and resources on setting up and maintaining database infrastructure.

Learn how to use API Builder to expose APIs from a Javascript SDK.