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

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.

Categories

More from Cloud

IBM Cloud inactive identities: Ideas for automated processing

4 min read - Regular cleanup is part of all account administration and security best practices, not just for cloud environments. In our blog post on identifying inactive identities, we looked at the APIs offered by IBM Cloud Identity and Access Management (IAM) and how to utilize them to obtain details on IAM identities and API keys. Some readers provided feedback and asked on how to proceed and act on identified inactive identities. In response, we are going lay out possible steps to take.…

IBM Cloud VMware as a Service introduces multitenant as a new, cost-efficient consumption model

4 min read - Businesses often struggle with ongoing operational needs like monitoring, patching and maintenance of their VMware infrastructure or the added concerns over capacity management. At the same time, cost efficiency and control are very important. Not all workloads have identical needs and different business applications have variable requirements. For example, production applications and regulated workloads may require strong isolation, but development/testing, training environments, disaster recovery sites or other applications may have lower availability requirements or they can be ephemeral in nature,…

IBM accelerates enterprise AI for clients with new capabilities on IBM Z

5 min read - Today, we are excited to unveil a new suite of AI offerings for IBM Z that are designed to help clients improve business outcomes by speeding the implementation of enterprise AI on IBM Z across a wide variety of use cases and industries. We are bringing artificial intelligence (AI) to emerging use cases that our clients (like Swiss insurance provider La Mobilière) have begun exploring, such as enhancing the accuracy of insurance policy recommendations, increasing the accuracy and timeliness of…

IBM NS1 Connect: How IBM is delivering network connectivity with premium DNS offerings

4 min read - For most enterprises, how their users access applications and data is an essential part of doing business, and how they service those application and data responses has a direct correlation to revenue generation.    According to We Are Social’s Digital 2023 Global Overview Report, there are 5.19 billion people around the world using the internet in 2023. There’s an imperative need for businesses to trust their networks to deliver meaningful content to address customer needs.  So how responsive is the…