Home
- Home
- Blog
Author :
Global TechHub
Introduction
In this article, you will learn how
to create new API using IBM API Connect. Using the graphical design tools and
source editor, you will create a new API called Hello World API which will
return the greeting message based on requested name.
In my previous article you can lean
how to setup IBM API Connect instance/environment in IBM Could.
Overview
Create the API and API Definition
Step 1: Click on the + Add button and New API.
Step
2: Enter the appropriate information to create a REST API
definition.
Title: Hello World API
Name: helloworld-api
Base
Path: /helloworld
Version: 1.0.0
You do not add a product at this
time, click Create API.
If the API Editor help screen
appears, click the sentence Learn more about composing APIs, or click Got it!
to access the main screen immediately.
Step 3: In the side bar,
select Paths to display
the Paths panel. Create a
new path by clicking the Add Path icon
.
In the Path field,
replace the default path segment with /greeting.
When an operation is called, this path segment
is appended to the URL of your API.
By default, a single GET operation is
already in your Path. Click the GET button to expand the setting dialog.
Step 4: In the side bar, click Definitions to display the Definitions panel. Add a Definition by clicking the Add
Definition icon
.
Expand your new definition by clicking new-definition-1. For the Name
field, enter greeting, and a Description of The format of the greeting object.
Using the same Definitions
panel, edit the default property and then create new properties by clicking Add
Property and editing the default values. In our case I am renaming new-property-1 to message.
Step 5: In the side bar, select Paths
to display the Paths panel. For the
/greeting Path, click GET to
expand the available settings. Include the greeting
definition in the GET operation Status Code 200 response by clicking the Schema
field and selecting greeting from
the drop-down list.
Step 6: In the submenu navigation bar, click the Assemble tab to
open the assemble view.
Delete the default Invke Activity. Drag and drop gateway script to pallet as shown
below.
Step 7: Access the invoke policy property sheet by clicking the gateway script label.
Update the following details as shown below.
Step 8: Click the Save icon
The Save icon. to save your changes.
Click the Source tab to view the
OpenAPI (Swagger 2.0) definition of your API. All the configuration you have
performed is included in this definition, either as part of the standard
OpenAPI (Swagger 2.0) schema, or as part of the x-ibm-configuration extension.
Testing the REST API
Click the Assemble tab.
Click the Test icon. The test tool opens, overlaying the palette.
Enter product name as ‘Hello World Product’ and click on create and publish.
Than click on next.
In the Operation section, use the
drop-down menu to select the get /greeting/{name}
operation.
At the bottom of the section, enter name
as ‘Ameer’ click Invoke. The
operation is called by the test tool. The response of your API is shown in the
test tool as shown below.
Conclusion
In this article, we learnt Creating a
REST API definition and Tested a REST API. In other articles you get a chance
to test the API by using the Developer Portal and API Manager test tools, both
of which run online.
Download
S. No
|
File Name
|
Size
|
Download
|
1
|
Hello World API in IBM API
Connect.pdf
|
1.0 MB
|
|
2
|
Helloworld_1.0.0.yaml
|
2.0 KB
|
Comments
Post a Comment