+ All Categories
Home > Documents > Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content ›...

Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content ›...

Date post: 30-May-2020
Category:
Upload: others
View: 31 times
Download: 0 times
Share this document with a friend
22
Creating a proxy REST API with IBM API Management 3.0.0.1 Creating a proxy REST API with IBM API Management 3.0.0.1 © 2014 Copyright IBM Corporation 1 of 22
Transcript
Page 1: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Creating a proxy REST API with

IBM API Management 3.0.0.1

© 2014 Copyright IBM Corporation 1 of 22

Page 2: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

TABLE OF CONTENTS

OBJECTIVE .................................................................................................................................... 3

PREREQUISITES ........................................................................................................................... 3

CASE STUDY ................................................................................................................................. 3

USER ROLES ................................................................................................................................. 4

BEFORE YOU BEGIN .................................................................................................................... 5

LOG INTO THE API MANAGER .................................................................................................... 6

CREATE A LOANS REST API ....................................................................................................... 7

CREATE A LOAN QUOTE PROXY RESOURCE .......................................................................... 9

CREATE A PLAN ......................................................................................................................... 15

TEST THE LOAN QUOTE RESOURCE ...................................................................................... 19

SUMMARY .................................................................................................................................... 22

© 2014 Copyright IBM Corporation 2 of 22

Page 3: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Objective This is the first tutorial in a series which will teach you to use IBM API Management 3.0.0.1 to create and test a number of different APIs. As this is the first in the series it covers the creation of a plan which is required for the following tutorials.

In this tutorial you will learn: How to create a REST API which proxies an existing REST endpoint How to create a Plan and add a resource to it How to test a REST API using the integrated test tool

PrerequisitesFor this tutorial it is assumed that you belong to a provider organization on an IBM API Management 3.0.0.1 cloud. In order for this to be true a system administrator will have created a provider organization via the Cloud Management Console (CMC). You will become a user within this provider organization via one of two methods:

• The system administrator will have made you the owner of the organization when creating it. • The owner of the organization will have invited you to join the organization.

In either case you will have received an email including a link to register your user. Once registered you will be sent through to the APIManager user interface which is the starting point for this tutorial.

Case studyBank A has an existing set of REST based services that they would like to expose through APIs in order to foster growth within the mobile and device market. The Bank A business team knows that an increased mobile and device application presence will enhance their brand image and increase customer satisfaction.

After considering building their own API management solution, the Bank A technology team has decided to implement an IBM API Management solution as it will allow them to enter the market quickly at a reduced cost.

In this tutorial you will develop the Bank A API Management solution. The solution will include the documentation and definition of a pure proxy to access the loan quote REST service as shown in Figure 1 below. This simple proxy allows Bank A to monitor the use of the service and restrict access to the API.

© 2014 Copyright IBM Corporation 3 of 22

Page 4: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

IBM API Management

Loan Quote Service

GET /quote?loanAmount=<amount>&annualInterestRate=<rate>

&termInMonths=<term>

loanAmount, annualInterestRate,termInMonths, monthlyPaymentAmount

GET /quote?loanAmount=<amount>&annualInterestRate=<rate>

&termInMonths=<term>

loanAmount, annualInterestRate,termInMonths, monthlyPaymentAmount

Figure 1 - Loan Quote REST Proxy

User rolesIBM API Management v3 allows different roles to be assigned to users. For more details of the different user roles and descriptions of them please see the following page in the Knowledge Center:

Adding users and assigning roles

This tutorial has been written assuming that you are an Administrator or Organization Owner. If you are another role, such as Product Manager or Developer then some of the required functionality will not be available to you so you may need to contact an Administrator or Organization Owner to perform certain actions, such as:• Access to create or edit environments is not available to Product Managers or Developers.• The ability to edit APIs is not available to Product Managers.

© 2014 Copyright IBM Corporation 4 of 22

Page 5: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Before you begin

Access the Bank A Backend Service

Before you setup an API in the IBM API Management product, you need to verify that the backend loan quote service is working and accessible. Remember that the goal is to expose this service as a managed API on the IBM API Management platform.

1. Open a new browser tab and navigate to the URL http://banka.mybluemix.net/home/index.html

2. Click on the example URI endpoint for the service titled Loan Service (JSON) to make sure that the loan quote service is operational. This is the service that you would like to expose via the API gateway. By clicking on the link you are making a REST based GET call to the loan quote service, passing the query parameters in the URL.

NOTE: Keep the Quote Service browser tab open for later in the tutorial as you will need some information from it.

© 2014 Copyright IBM Corporation 5 of 22

Page 6: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Log into the API Manager

3. Open a new browser tab and navigate to the URL https://<managementserver>/apimanagerWhere <managementserver> is the IP Address or hostname of your management server.

4. Sign in to the IBM API Management platform by entering your credentials and clicking Sign in.

5. After you sign in, the API Manager Home page is displayed. The home screen displays activity graphs for the most active APIs and Applications.

6. At the top of the screen, the primary banner contains a drop down list for your organizations and your login name. You must belong to an organization to use the API Manager UI.

© 2014 Copyright IBM Corporation 6 of 22

Page 7: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Create a Loans REST API

Now that you have logged into the API Manager, you can start creating a REST API to expose and manage Bank A’s loan quote service.

7. Select APIs from the navigation pane. This will take you in to the Draft APIs view, from here you can add new REST or SOAP APIs and edit existing ones.

8. Click the + REST button to create a new REST API.

© 2014 Copyright IBM Corporation 7 of 22

Page 8: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

9. Populate the fields as shown in the table below. When complete, click the Add button. This will add the API to the Draft APIs list.

Field Name Value

API name Loans

Path loans/v1

API description Operations related to Bank A loans

Note: The Path specified here will become part of the URL which is eventually called so will need to be valid for this use.

© 2014 Copyright IBM Corporation 8 of 22

Page 9: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Create a Loan Quote Proxy Resource

10.Click on the Loans link to define the specific resources that are available for the API.

11.Review the Loans REST API. The API identification and authentication requirements are displayed beneath the titles "Identify Application Using" and "Authenticate Application Users Using". You can also upload or link to external documentation for the API.

Check that Identify Application Using is set to Client ID.

© 2014 Copyright IBM Corporation 9 of 22

Page 10: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

12.To create a single quote resource that supports a GET operation, click + Resource.

13.By default, the HTTP methods GET and POST are displayed. Remove the POST method by clicking the X inside of the Post button

© 2014 Copyright IBM Corporation 10 of 22

Page 11: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

14.Populate the fields as shown in the table below. Check that Identification is selected for this resource. When complete, click the Add button.

Field Name Value

Path quote?loanAmount=20000&annualInterestRate=0.9&termInMonths=52

Display Name Quote

Description Loan quote

15.Now that the quote resource has been defined, click on the Edit icon to edit the resource details.

© 2014 Copyright IBM Corporation 11 of 22

Page 12: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

16.The query parameters from the Path you supplied are listed in the Parameters panel. Select the Required check box for each parameter and enter a description for each one as listed in the table below.

Parameter Description

loanAmount Total loan amount

annualInterestRate Annual interest rate (%)

termInMonths Duration of the loan (in months)

17.To retrieve the details of the quote status service to use in the resource definition, select the Bank A browser tab or go to the following URL in a different browser tab or window:

http://banka-rs.mybluemix.net/loans/v1/quote?loanAmount=20000&annualInterestRate=0.9&termInMonths=52

18.Copy the JSON response to the clipboard (Type CTRL-A to select the JSON response and CTRL-C to copy the text)

19.Switch back to the API Manager tab or window.

© 2014 Copyright IBM Corporation 12 of 22

Page 13: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

20.Click on the Response Body tab and paste the JSON response you just copied (Type CTRL-V to paste). Click somewhere else on the screen and the JSON will be automatically formatted for you.

21.For this resource you will simply proxy the existing service. Select the Implementation tab and click the Proxy button

22.Return to the Bank A browser tab or window

23.Copy the URL without the query string from the web browser’s address bar (Select the URL without the query string and type CTRL-C to copy)

24.Go back to the API Manager browser tab or window.

© 2014 Copyright IBM Corporation 13 of 22

Page 14: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

25.Paste the URL of the JSON service into the Proxy URL field (Type Ctrl+V to paste) and click Save API. The red asterisk against the resource should disappear indicating there are no unsaved changes.

Proxy URL

http://banka-rs.mybluemix.net/loans/v1/quote

You have now defined your first REST API. The example response text will help developers who are creating applications and integrating with the Bank A Loan API for the first time. The example is also used by the API Manager to configure the proxy itself so no coding is required.

© 2014 Copyright IBM Corporation 14 of 22

Page 15: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first
Page 16: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

27.A plan is a packaging construct by which APIs are made available to consumers. A plan makes available a collection of resources from one or more APIs, and is published to consumer organizations. Application developers, which are part of the consumer organizations, gain access to APIs by registering their applications to access plans. A plan carries with it a collection of policy settings. In its simplest form, a plan defines a single quota policy that applies to all the API resources that are accessed through the plan.

Click + Plan to create a new plan.

28.Populate the fields as shown in the table below. When complete, click the Add button.

Field Name Value

Plan Name Public

Plan Description Open APIs accessible by any developer

© 2014 Copyright IBM Corporation 16 of 22

Page 17: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

29.The Public plan will immediately appear in the list of available plans. To edit the plan you need to click on the plan name. Click on Public.

30. In order to expose the resource you have created you need to add it to the Public plan.Click + Resource

© 2014 Copyright IBM Corporation 17 of 22

Page 18: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

31.Ensure that Loans is the selected API in the left hand column, then select the Loan quote resource you previously created. Click Add.

32.The resource is added to the Public plan. If required, you can set rate limits for the resource or plan as a whole from this editor. At the moment you are going to leave these as unlimited but you will be setting rate limits in a later tutorial. You now have the resource added to the plan so you can save the plan and test your resource.

Click Save

© 2014 Copyright IBM Corporation 18 of 22

Page 19: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Test the Loan Quote Resource

The API Manager UI contains an integrated test tool which allows an API Developer to invoke APIs deployed within a plan deployed to a given environment. You have just created the Public plan and added your resource to it. API Management 3.0.0.1 creates a Sandbox environment for your organization, it is this which we are going to use for testing the resource.

33.To test your REST resource to ensure that it is defined and implemented correctly, select APIs from the navigation pane.

© 2014 Copyright IBM Corporation 19 of 22

Page 20: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

34.To edit the API you need to click on the name. Click on Loans.

35.Click the Edit icon for the GET quote resource.

36.Click the Test tab.

© 2014 Copyright IBM Corporation 20 of 22

Page 21: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

37.The Test fields should automatically be correctly populated because there is only one Environment and Plan in your organization, however, if you are working in an organization where this isn't the case select the Sandbox environment and the Public (Version 1) plan.

Enter the parameter values in the table below and click the Invoke button.

Parameter Value

loanAmount 10000

annualInterestRate 1.5

termInMonths 36

38.Confirm that the correct response was returned and a 200 response code.

© 2014 Copyright IBM Corporation 21 of 22

Page 22: Creating a proxy REST API with IBM API Management 3.0.0 › apimanagement › wp-content › ...Creating a proxy REST API with IBM API Management 3.0.0.1 Objective This is the first

Creating a proxy REST API with IBM API Management 3.0.0.1

Summary

In this tutorial you have seen:

How to create a REST API which proxies an existing REST endpoint How to create a Plan and add a resource to it How to test a REST API using the integrated test tool

This is the first in a series of tutorials which will cover the features of API Management 3.0.0.1. For more information about this series and other tutorials please see:

http://developer.ibm.com/apimanagement

End of Tutorial

© 2014 Copyright IBM Corporation 22 of 22


Recommended