IBM and Red Hat — the next chapter of open innovation. Learn more ›
Divya Mallya | Published March 25, 2018
API Connect for IBM Cloud is an integrated API management offering, where the API lifecycle and the actions that surround it are performed within the offering. The steps of the API lifecycle include creating, running, managing, and securing APIs.
In this tutorial, the reader will learn how to:
This tutorial will take you through the following major tasks:
From a shell enter the following command, it is used to create and manage LoopBack applications:
At the prompt, enter test-project as the project name. Press Enter.
What's the name of your application? `test-project`
Enter the name of the directory in which to create the project. You can press Enter to use a directory with the same name as the project, or type a new name and press Enter.
Enter name of the directory to contain the project: `test-project`
Select the version of LoopBack to use. Choose the current production version, 3.x by using the arrow keys.
Which version of LoopBack would you like to use? `3.x (current)`
Specify the kind of application that you want to create by using the arrow keys to select empty-server. Then, press Enter to create an empty LoopBack API project.
What kind of application do you have in mind? (Use arrow keys)
->empty-server (An empty LoopBack API, without any configured models or datasources)
hello-world (A project containing a basic working example, including a memory database)
notes (A project containing a basic working example, including a memory database)
An empty LoopBack project contains the directories seen below.
In command prompt change directories to your LoopBack project (test-project) and enter the following command
After a while, the console displays this message.
Express server listening on http://127.0.0.1:9000
API Designer opens in your web browser, initially displaying the login page if you haven’t logged in recently. The login page prompts you to Sign in with IBM Cloud. Enter your IBM Cloud credentials, which authenticates you on IBM Cloud and provides access to the API Manager features such as Publish, Explore, and Analytics. You will continue to work in API Designer locally to create APIs, models and data sources.
By default, the Connector setting shows In-memory db and the other settings are blank. Keep the default settings and API Designer automatically saves the new data source.
Note: The In-memory data source is built in to LoopBack and is suitable only for development and initial testing. When you are ready to connect your models to a real data source such as database server, change the Connector setting accordingly then install the data source connector.
Click the Save icon on top right corner.
Enter CUSTOMER in the Name text field, then click New.
Note: The name of the model should be same as that of the DB table name, when using in-house database.
In the Data Source field, select CustomerDS from the drop-down.
In the Properties section, click the Add property icon.
Note: Add a property for each column of the table, with the same data type while using any in-house database.
Note: Make ID property field as Required and also mark it as ID (primary key).
Start the local test servers by going to the test console at the bottom of the screen (API Designer), click the Start the servers icon.
Start the servers
Wait until the Running message is displayed: Depending on your project configuration and whether other processes are running, different port numbers might be displayed.
Click on Explore tab situated in top header bar. You will see the API Explore tool. The side bar present in left, shows all the REST operations for the LoopBack models in the API. Models that are based on PersistedModel by default have a standard set of create, read, update, and delete operations.
Click the operation CUSTOMER.create in the left pane to display the endpoint.
Note: The center pane displays summary information about the endpoint, including its parameters, security, model instance data, and response codes. The right pane provides template code to call the endpoint using the curl command, with a drop down menu to choose languages such as Ruby, Python, Java, and Node.
To test the REST endpoints in the API Explore tool, on the right pane click Try it, and then scroll down to Parameters and click Generate to generate some dummy data. By default, the generated data includes the properties defined for the endpoint, for example:
Click Call operation to call the endpoint with that data. You should see the request and response parameters, along with the JSON instance data that you entered.
To confirm that the operation added a model instance, click CUSTOMER.find then click Call operation with no filters to display all CUSTOMER instances. An example result (with two model instances) would look like this:
This completes creating, configuring a LoopBack application locally and testing it.
To publish the API Product to IBM Cloud, you must have registered for an IBM Cloud account and created an instance of API Connect in IBM Cloud. For details, see Creating an instance of API Connect for IBM Cloud.
You must have the API Designer open (if not already) by running apic edit from command line after changing the directory to your LoopBack project.
Add and Manage Targets
Add IBM Cloud target
Click Publish again and select the target you just added. You’ll see the Publish dialog:
Select Publish application and Stage or Publish products, then select specific products. Select test-project, and then click Publish. This would publish the LoopBack applicaiton to IBM Cloud and API Product to your API Connect instance on IBM Cloud.
Stage or Publish products
The console where you started the API Designer displays a number of messages. If the application is successfully published, then you will see messages in the console similar to the following:
Return to the API Connect Dashboard on IBM Cloud. Click the chevron icon and choose Dashboard from the dropdown menu.
Click the Sandbox Catalog then click test-project. You’ll see the application details:
This completes the publishing LoopBack application and API Product to IBM Cloud using API Designer.
In the API Connect Dashboard on IBM Cloud, click the chevron icon and choose Dashboard from the dropdown menu.
Click the Sandbox Catalog.
In Sandbox, click Settings -> Portal
Select IBM Developer Portal in Portal configuration.
IBM Developer Portal
After a few minutes, you receive an email with a link to your Developer Portal site for that Catalog. When this is available you can use that link to access your site. Once the developer portal site is ready and admin password is reset, you need to create a developer account to test APIs.
Open a Developer Portal at the previously specified URL, then clickCreate an account tab and complete the fields. If the Create an account link is not visible, log out as Admin account from the Developer Portal first.
Create an account
Note: Your email is used as your user name for the Developer Portal. The email address for creating developer account must be different from the address used for creating the administrator account.
Click Create an account. Your Developer Portal site is activated and you receive a confirmation email as a result. Click the account activation link in the confirmation email to activate your account.
Create new app
Scroll down and select GET /CUSTOMERS and then scroll to the right pane of the display, Enter <Client Secret value> noted down earlier. Click on Call Operation
<Client Secret value>
Notice the request and response displayed.
Similarly secured REST APIs for all CRUD operations are available. Without client ID and client secret values (which are obtained during app registration) APIs will not provide any output. Hence only registered apps can consume the APIs.
In this how-to the reader has gone through a step by step guide on how a provider organization can securely expose REST APIs to developer organizations using API Connect.
Developer toolkit tutorials
Developer portal tutorials
May 16, 2019
API ManagementArtificial intelligence+
Learn the basics on how to perform a few CRUD operations against an Elasticsearch cluster on IBM Cloud with Postman.
Write a cloud Java microservice that connects a Databases for MongoDB datasource and showcases sample CRUD operations.
Back to top