Creating an API Gateway using the UI.
An API gateway provides a single, unified API entry point across one or more internal APIs. You can use it to create, secure, share, and manage APIs that access IBM Cloud resources. When a client makes a request, the API gateway intercepts an incoming API call and executes security policies, and then routes the call to the backend application. After the request is processed, the backend application sends the response to the gateway, which then routes it back to the caller.
In this article, we’ll explore how to create a simple API Proxy with and without an API key.
Table of contents
- Section 1: Create an API proxy
- Section 2: Test and invoke the API without the clientID/apiKey
- Section 3: Test and invoke the API with the clientID/apiKey
Prerequisites
- You’ll need an IBM Cloud Account.
- It is mandatory to create a Cloud Foundry org and space to your created account. For additional information, refer to the creating organizations and spaces resource.
Section 1: Create an API proxy
Step 1: Log in to IBM Cloud.
Step 2: On the Dashboard, click on the Navigation menu and select API Management:
Step 3: In the navigation list, expand API Gateway and click Services:
You’re now ready to create a simple API proxy.
Step 4: Click on Legacy API Gateway:
Step 5: Click Create API.
Step 6: Select Create an API proxy. An API proxy defines configuration settings for an external API so that you can call it from IBM Cloud apps:
Step 7: On the Create an API Proxy page, complete the fields to configure a proxy.
Let’s walk you through the process of creating a new proxy:
- Download the findbranch.txt file to your local filesystem. Rename this file to
findbranch.yaml
. - Click on API definition:
- Click the Import YAML or JSON option and select the
findbranch.yaml
. - The API name is auto populated with ‘FindBranch’.
- The Base path for API is ‘/findbranch’.
- Set the URL of the External endpoint where the new API proxy routes traffic from IBM Cloud: https://apictutorials.mybluemix.net/branches. This defines the target URL that the platform invokes on a request to the API proxy. The endpoint will look like the following:
The API Proxy page will look like the following:
- By default, the CORS field is set to Enable CORS – Add CORS headers to API responses:
- Under IBM Cloud Settings, by default, an IBM Cloud location, Cloud Foundry organization, and Cloud Foundry space for this API proxy is set:
Step 8: Click Create. The configuration to create the new API Proxy is now complete.
The information about it displays on the Monitor page. This page provides the API endpoint and a status indicator (when the API is online, it is available for use):
The API route includes the region, which represents the geographic area where your APIs reside. For example, if the route displays as — https://25328c20.us-south.apigw.cloud.ibm.com/findbranch — then the region is us-south.
Section 2: Test and invoke the API without the clientID/apiKey
Step 1: In the navigation list, click Review and test:
Step 2: Choose the HTTP verb supported by the backend. In this case: GET /details:
Click Try it. Leave the Client ID field blank.
Step 3: Click the Send button. Because the backend website supports the GET /details request, it returns a successful response similar to the following:
Step 4: You can validate the request using Postman. Postman is an API development tool which helps to build, test, and modify APIs. In Postman:
- Set your HTTP request to GET.
- In the request URL field, input the Endpoint copied from the GET : /details page.
- Click Send.
- You will see Status 200 OK Message.
- There should be results shown in the body [click Raw] which indicates that your test has run successfully:
Section 3: Test and invoke the API with the clientID/apiKey
In this section, we’ll enhance security by using the system-generated API key. Here, you are required to pass the API key as the x-ibm-client-id header of each incoming request.
Step 1: In the navigation list, select Define and Secure:
Step 2: Enable Require application authentication via API key:
Step 3: Click the Save button.
Step 4: In the navigation list, select Manage sharing and keys:
Step 5: Click Create API key:
Step 6: Enter a descriptive name for the API key and click the Create button:
Step 7: From the navigation list, click on Review and test option. Select GET /details.
Step 8: Select Try it. Click Send without entering any input in the “Client ID” field. It returns a response similar to the following:
Step 9: Now copy the API key from Manage sharing and keys and enter it into the Client ID field.
Step 10: Click the Send button:
It returns a successful response.
Step 11: Validate the same request on Postman:
- Set your HTTP request to GET.
- In the request URL field, input the Endpoint copied from the GET : /details page.
- In Authorization, set the type as API Key. Set the ‘x-ibm-client-id’ as the variable for Key.
- Enter the API key into the Value field.
- Click Send.
- You will see Status 200 OK Message
- There should be results shown in the body [click raw] which indicates that your test has run successfully:
It returns a successful response.
Conclusion
This article was focused on how to create a simple API Proxy and also test and invoke the API with and without the clientID/apiKey.
- For more information on the API gateway service, see the IBM Cloud docs.
- For defect or support needs, use the Support section in the IBM Cloud menu.
- To get started with any of the IBM Cloud services, check them out in the IBM Cloud Catalog.