With IBM API Connect, you can have a live API up and running in just a few minutes. Just follow these steps!
Before you begin, make sure you have the following:
Install API Connect
To get API Connect from NPM, run the following from the command line:
$ npm install -g apiconnect
This installs the API Connect development tools on your system. Mac users may need to run this command as ‘sudo’ depending on their system permissions.
Create your API Connect project
To begin creating your API Connect project, run the following and follow the prompts. This will create a directory that contains a basic API Connect project called ‘apic-getting-started’:
$ apic loopback
| | .--------------------------.
|--(o)--| | Let's create a LoopBack |
`---------´ | application! |
( _´U`_ ) '--------------------------'
| ~ |
´ ` |° ´ Y `
[?] What's the name of your application? apic-getting-started
[?] Enter name of the directory to contain the project: apic-getting-started
[?] What kind of application do you have in mind?
empty-server (An empty LoopBack API, without any configured models or datasources)
Run the API Designer
Next, navigate to the project directory and open the API Designer to start working with our project:
$ cd apic-getting-started
$ apic edit
Express server listening on http://127.0.0.1:9000
The API Designer will start locally, then open the UI in your default browser. If you are not logged into IBM Bluemix, you will be prompted to log in with an existing account, or to register for a new account.
Once you are logged in, the API Designer will display the ‘APIs’ tab. You will see an API has already been created for you.
Create a new data model
Data models represent resources that can be consumed and exposed by your APIs. These models are linked to Data Sources, such as databases, external services like email, and even other APIs.
Let’s define a new data model.
- Click ‘Models’ in the top navbar
- Click the ‘+ Add’ button.
- When prompted, enter the name ‘customer’ for the new data model.
- Click the ‘New’ button. The data model settings will be displayed.
Customize your data model
Notice the default Base Model is ‘PersistedModel’. This means this data model represents a database record. It also has a Data Source called ‘db’. This is the default in-memory database.
In this example, we are creating customer records, so any operations performed on the ‘customer’ data model will act on records stored in the ‘db’ Data Source.
Let’s make a couple modifications to your data model:
This automatically creates a publicly accessible API endpoint called ‘/customers’ with standard CRUD (create, read, update, delete) operations. For example, a GET request to ‘/customers’ will return a set of customer records from ‘db’.
- In ‘Properties’, click the ‘+’ button to add a new property to the data model.
- Set the ‘Property Name’ field to ‘name’.
- Select ‘Required’. This will require all instances to have this property set.
- Select ‘Type’ of ‘string’.
- Click the save icon. This is a floppy disc icon in the upper right of the screen.
Start your API
API Connect makes it easy to run and test changes to your API locally. Just do the following:
- Click ‘All Models’ to return to the ‘Models’ page.
- Click the ‘Publish’ button.
- Click the ‘Start’ button. Once the API has started, the local address where it is running will be displayed.
Explore your API
You can now send requests directly to this API, or use the API Connect Explorer. The Explorer offer a easy-to-use UI that lets you view all of the operations and endpoints of your API.
To open the Explorer, click the ‘Explore’ button.
Features of the Explorer include:
- Browsable list of all API endpoints and operations.
- Full documentation
- Sample requests, including cURL and API Connect SDKs.
- Sample responses
Try it out!
Once your API is running, you can test it using the provided code samples, or try it out right inside the Explorer. To test an endpoint with the Explorer, simply navigate to the endpoint you want to try, set the request parameters, and click the ‘Call operation button’.
Publish your API
Now that you’ve tried running your API locally, it’s time to publish it. API Connect supports publishing your API to services that supports a Node.js runtime, and will soon include IBM Bluemix as well.
For complete instructions on how to publish your API, see the IBM documentation: