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

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

24 IBM offerings winning TrustRadius 2024 Top Rated Awards

2 min read - TrustRadius is a buyer intelligence platform for business technology. Comprehensive product information, in-depth customer insights and peer conversations enable buyers to make confident decisions. “Earning a Top Rated Award means the vendor has excellent customer satisfaction and proven credibility. It’s based entirely on reviews and customer sentiment,” said Becky Susko, TrustRadius, Marketing Program Manager of Awards. Top Rated Awards have to be earned: Gain 10+ new reviews in the past 12 months Earn a trScore of 7.5 or higher from…

IBM Tech Now: April 8, 2024

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 96 On this episode, we're covering the following topics: IBM Cloud Logs A collaboration with IBM watsonx.ai and Anaconda IBM offerings in the G2 Spring Reports Stay plugged in You can check out the…

IBM Newsletters

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