API Builder Getting Started Guide


You should have NPM (minimum 5.7) and Node.js (minimum 8.9) installed.

Getting started

 Install the API Builder Command Line Interface (CLI) globally using npm.

Install API Builder
[sudo] npm install -g @axway/api-builder

Once API Builder CLI is installed, you can use it to create a new project.  In the following example, the CLI will create and initialize the ./myproject new project directory.

Initialize a new project
api-builder init myproject

Then, install the project's dependencies and start the API Builder project.

Run project
cd ./myproject
npm install --no-optional
npm start

Once your project is running, point your browser to http://localhost:8080/console to access the API Builder user interface (UI) console.

Upon reviewing the left navigation, you can navigate to the following items:

Summary Your app's admin home page.
API Doc & Test Auto-generated documentation about your API endpoints. Provides help for the client application to access your application.
Models Interface to help you build models. A model represents data stored from another source.
Configurations Lists configuration files that you can modify and save within a browser.
Connectors Lists and filters installed connectors.
View Documentation Links to the Axway documentation site for API Builder's guide.
Sidebar toggle Toggles the width of the sidebar.

The Admin Console is not deployed in Production installs of your application:

npm install --production

It can also be disabled by changing the configuration settings in the conf/default.js file. For now, let's explore some of the features of the Admin Console.

Create a new model

Let's create a new model using the Admin Console. In the Admin Console,

  1. Click the Models tab. 
  2. Click the + Model button on the right side.
  3. In the New Model step:

    1. Enter "simpleuser" in the Model name field (required). The name must be unique for all of the application's models.
    2. Select a Connector from the drop-down list (required). Connectors are used to persist data to the model.
    3. Add a description.
    4. Click Next to move onto the fields step.
  4. In the Create Model Fields step:

    1. Click the + Field button.
    2. Enter "first_name" in the Field name field (required).
    3. Set Type to String.
    4. Leave Default value empty.
    5. Add a description.
    6. Check the boxes for Read-only or Required as necessary.
    7. Click the Add field to model button.
    8. Repeat step 4 as necessary to add the "last_name" and "email" fields to this model. After you add the fields, you can configure them by changing properties or adding validation or return logic.
    9. Click Next to move onto the endpoint step.
  5. In the API endpoint page:

    1. Make sure the CreateRetrieve, and Update methods are checked. Since the Delete methods checkbox is not checked, the DELETE api/simpleuser and the DELETEALL api/simpleuser endpoints will not be generated but all the other default endpoints for this model will be.
    2. Click Save to commit your new model to the app.

If you look in your project's models folder, notice you have a new file called simpleuser.js. This file was just created by the Admin Console. Instead of creating a model using the Admin Console, you can define one using JavaScript files in the project's models directory.

Access model data

Now that you have created the simpleuser model, let's try to retrieve the model data from the application. In the Admin Console:

  1. Click the API Docs & Test tab. This page lists all the API endpoints that your application exposes. You can also add or import API endpoints via the + API button. For additional information, refer to Manage Endpoints.
  2. Click anywhere on the row of any one of the API endpoints that you recently created. The Admin Console presents all the API endpoints that can be used to access a particular model. You can also export API endpoints via the Download Swagger button. For additional information, refer to Manage Endpoints.
  3. Expand one of the GET methods in your endpoint. The code example for the curl should be visible. If it's not, scroll down until the Examples section is visible and select curl.
  4. Copy a curl command and run it in a terminal. Note the message returned by this command. Alternatively, you can test the select GET method in the user interface. Scroll until the Test API section is visible, if available complete the Request, Path parameters, and Query parameters fields, and then click Execute. Note the Result returned in the user interface.

Running your API Builder application

Starting API Builder projects will launch the runtime and the UI, which is used to edit your project. By default, the UI will bind to http://localhost:8080. If you wish to change this, you can edit your conf/default.js and add a port key/value. For example:

Change port via config
// The port for the UI
port: 8000,

Providing environment-specific configuration

You can choose which configuration values you want to be configurable from the environment by explicitly setting them at process.env. For example, to make the port configurable you could do:

// The port for the UI
port: parseInt(process.env.PORT) || 8000,

This allows you to create containers for your application that can be configured when the container is being started.

Related Links