Apigee - API Management - Part 2.1

Apigee - API Management - Part 2.1

Build your first API with Google's Apigee

Introduction

In the last edition of this series, we saw the basics of the API life cycle and API life cycle management. If you missed it, you can read it here.

With that basic knowledge in place, we will start our journey with the API Life Cycle management tools.

Now, there are quite a few offerings that one can choose from, namely WSO2 APIM, Apigee, AWS API Gateway etc. and each of them has their own set of pros and cons, which we will definitely try to cover in a comparison in the future. For now, we will begin by getting to know these tools in detail one after the other.

With that said the tool that we are focusing on in this article is Google's Apigee.

Google Apigee

Apigee is one of the largest API Management platforms out there today. It boasts about the recognition that it got in the recent Gartner report. Gartner is a global research and advisory firm that provides information, advice and tools for leaders in IT, Finance, HR, Customer Service and Support, Communications and other verticals of business. Their research about the market trends that they put out is considered as benchmarks by a lot of big corporations. In simple terms, get Gartner to write about your product/services and see it scale.

Apigee Corp. was an API management and predictive analytics software provider before its merger into Google Cloud. It was founded in 2004 as Sonoa Systems founded by Raj Singh and Ravi Chandra before being rebranded as Apigee in 2010. Apigee was acquired by Google in a deal worth $625 million in 2016.

Fun fact: Apigee also powers Netflix's APIs.

With that context, let's see how Apigee works and how we can use it to manage our own API lifecycles.

Pre-Requisites

1) Basic knowledge of API Management tools.

2) An Apigee account. If you don't have one, please create a trial account at Apigee here.

Setting up API proxies and security

Today, we will be focusing on the very basics of what you can do with the platform. Let's set up a simple API proxy and some basic API security.

Screenshot 2020-12-27 at 7.21.19 PM.png

Once you login you will be greeted with this dashboard, which on the top left corner shows the user's display name, the organisation ID, and in the center console, you have some quick launch actions.

So, a typical API Proxy in Apigee looks something like this:

ProxyToBackendWithFlows_v3.png

Now, we will learn how to design an OpenAPI specification for an existing HTTP service and store it within the Apigee platform. Then create an API proxy that routes inbound requests to an existing HTTP service.

Pre-requisites:

1) Basic understanding of OpenAPI Specification (FKA: Swagger).

2) Access to an HTTP client to test the API (eg. cURL, Postman, etc.). If you do not have access to one, you can use the Apigee Trace Tool or the Apigee REST client.

Note: During this run down, as you will be working within an Apigee Organization (Org) that is shared by multiple users, please prefix all asset names within the Org with your initials. For example, Spec name = {your-initials}_{spec name}, API proxy name = {your-initials}_{proxy name} etc.

Create an OpenAPI Specification**

During the course of this lab, we will expose as an API endpoint is the Hipster Products service located at http://cloud.hipster.s.apigee.com/products. First, we are going to design and create an OpenAPI specification for the different resource endpoints, i.e. /products and /products/{productId}.

1) Select Develop → Specs in the side navigation menu.

Screenshot 2020-12-27 at 7.51.01 PM.png

As we have a pre-designed sample of the spec available for this article, we will be importing it into your Apigee Org's Spec Store. Click +Spec, then click on Import URL to add a new spec from an existing source.

Screenshot 2020-12-27 at 7.53.05 PM.png

Enter spec details & replace {your-initials} with the initials of your name.

File Name: {your-initials}_hipster_products_api_spec

URL: https://imagedeliver.s3.us-east-2.amazonaws.com/Hipster.yaml

Screenshot 2020-12-28 at 11.52.35 AM.png

Verify the values and click Import.

Spec has now been imported into Apigee and is ready to use. You should see your spec in the list.

For example:

Screenshot 2020-12-28 at 11.53.27 AM.png

Click on {your-initials}_hipster_products_api_spec from the list to access the OpenAPI spec editor & interactive documentation that lists API details & API Resources.

Screenshot 2020-12-28 at 11.57.06 AM.png

Create an API Proxy

It’s time to create an Apigee API Proxy from an OpenAPI Specification. Click on Develop API Proxies from the side navigation menu.

Screenshot 2020-12-28 at 4.46.33 PM.png

Click +Proxy. The Build a Proxy wizard is invoked.

image_6.png

Select Reverse proxy, click on Use OpenAPI below the reverse proxy option.

The following is an image showing the selection of API Proxy type. User has selected Reverse Proxy and clicked Use OpenAPI Spec

image_7.png

You should see a popup with the list of Specs. Select {yourinitials}_hipster_products_api_spec and click Select.

Screenshot 2020-12-28 at 4.51.02 PM.png

Enter details in the proxy wizard. Replace {your-initials} with the initials of your name.

1) Proxy Name: {your_initials}_Hipster-Products-API

2) Proxy Base Path: /v1/{your_initials}_hipster-products-api

3) Existing API: Observe the field value which is auto-filled from the OpenAPI Spec.

Screenshot 2020-12-28 at 4.53.41 PM.png

Verify the values and click Next.

Select Pass-through (none) for the authorization in order to choose not to apply any security policy for the proxy. Click Next.

Screenshot 2020-12-28 at 5.04.02 PM.png

You can select which API resources, from the list configured in the OpenAPI Spec, should be exposed. Select all & Click on Next.

Screenshot 2020-12-28 at 5.05.07 PM.png

Go with the secure Virtual Host configuration. Ensure that the default one is unchecked.

Screenshot 2020-12-28 at 5.06.23 PM.png

Ensure that only the test environment is selected to deploy to and click Create and Deploy.

Screenshot 2020-12-28 at 5.08.27 PM.png

Once the API proxy is created and deployed, click Edit Proxy to view your proxy in the proxy editor.

Congratulations!

You have now built a reverse proxy for an existing backend service. You should see the proxy Overview tab.

Screenshot 2020-12-28 at 5.13.33 PM.png

Test the API Proxy

Let us test the newly built API proxy. You can use any HTTP client like cURL, Postman or the Apigee Trace Tool.

If you're using cURL:

org = Organization name env = Environment where API is deployed

curl -X GET "https://{{org}}-{{env}}.apigee.net/{{your initials}}_hipster-products-api/products"

If you're using Trace Tool:

Navigate to your proxy's Trace tab.

Ensure that the deployed API revision is selected.

Hit Start Trace Session.

Screenshot 2020-12-28 at 5.30.47 PM.png

Wait for Trace session to start.

Modify the URL to send to a valid API resource - append a /products to the end of the URL.

Hit 'Send'.

Screenshot 2020-12-28 at 5.34.15 PM.png

You will see that the API proxy received the request and sent back an HTTP status 200 response which was logged by the Trace session. You can click on the step shown below to view the response body:

Screenshot 2020-12-28 at 5.36.42 PM.png

Save the API Proxy

Let’s save the API Proxy locally as an API Bundle so that we can reuse it in the follow-up articles.

Save the API Proxy by downloading the proxy bundle. See screenshot below for instructions:

Screenshot 2020-12-28 at 5.40.39 PM.png

Final Words

You have now built and tested your first API Proxy to an existing backend. With this in place, in the follow-up articles, we will go through adding security to the API proxy and creating the first API Product that you can serve as a service to the world.

See you in the next one. 👋🏻