January 8, 2021 By Rashmi Ramachandra 6 min read

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.
Was this article helpful?
YesNo

More from Cloud

Fortressing the digital frontier: A comprehensive look at IBM Cloud network security services

6 min read - The cloud revolution has fundamentally transformed how businesses operate. Its superior scalability, agility and cost-effectiveness have made it the go-to platform for organizations of all sizes. However, this shift to the cloud has introduced a new landscape of ever-evolving security threats. Data breaches and cyberattacks continue to hit organizations, making robust cloud network security an absolute necessity. IBM®, a titan in the tech industry, recognizes this critical need, provides a comprehensive suite of tools and offers unmatched expertise to fortify…

How well do you know your hypervisor and firmware?

6 min read - IBM Cloud® Virtual Private Cloud (VPC) is designed for secured cloud computing, and several features of our platform planning, development and operations help ensure that design. However, because security in the cloud is typically a shared responsibility between the cloud service provider and the customer, it’s essential for you to fully understand the layers of security that your workloads run on here with us. That’s why here, we detail a few key security components of IBM Cloud VPC that aim…

New IBM study: How business leaders can harness the power of gen AI to drive sustainable IT transformation

3 min read - As organizations strive to balance productivity, innovation and environmental responsibility, the need for sustainable IT practices is even more pressing. A new global study from the IBM Institute for Business Value reveals that emerging technologies, particularly generative AI, can play a pivotal role in advancing sustainable IT initiatives. However, successful transformation of IT systems demands a strategic and enterprise-wide approach to sustainability. The power of generative AI in sustainable IT Generative AI is creating new opportunities to transform IT operations…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters