Getting Started

Red Hat 3scale API Management 2.13

Getting started with your 3scale API Management installation.

Red Hat Customer Content Services

Abstract

This guide provides information about how you can start working with 3scale.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.

Chapter 1. First steps with 3scale

For your first steps with Red Hat 3scale API Management features, you will learn how to integrate and manage your API, both from customer-facing and internal perspectives.

1.1. Products and backends for 3scale APIs

Red Hat 3scale API Management separates your APIs into two main groups:

  • Backends: Internal APIs bundled in a product. Backends grant API providers the freedom to map their internal API organization structure to 3scale.
  • Products: Customer-facing APIs. Products facilitate the creation of strong and simplified offerings for API consumers.

A product can contain multiple backends, and a backend can be used in multiple products. In other words, to integrate and manage your API in 3scale you need to create both:

  • A backend containing at least the URL of your API. The backend can optionally be configured with mapping rules, methods and metrics to facilitate reusability.
  • A product for which you define the application plans, and configure APIcast.

1.2. Configuring your first API using the 3scale wizard

The 3scale wizard provides initial assistance when working with products and backends.

Important

Run the 3scale wizard only the first time you log in to your 3scale account. If you run the wizard to create subsequent 3scale components, you will overwrite existing components.

Prerequisites

  • You need a 3scale account.

Procedure

  1. Run the wizard. You can run the 3scale wizard in two ways:

    • The first time you log in to your 3scale account.
    • Running the wizard by replacing [Your_admin_domain] in the following URL address:

      \https://[Your-admin-domain]-admin.3scale.net/p/admin/onboarding/wizard/intro

      For example, if your admin domain is testing-area, the wizard is available in:

      https://testing-area-admin.3scale.net/p/admin/onboarding/wizard/intro

  2. Click OK, how does 3scale work?.
  3. Watch the introductory animation. Once done, click Got it! Let’s add my API.
  4. Create a backend:

    1. Specify a name for your backend. For example: Inventory
    2. Indicate a base URL for the backend. Example: https://echo-api.3scale.net:443
    3. Click Add this Backend.
  5. Create a product:

    1. Indicate a product name. For example: Petstore
    2. Click Add this Product.
  6. Indicate a path to connect your backend to your product, and click Add the Backend to the Product.

    • You can leave the default value. Path: /
  7. To make a test with a GET request, click Send request.

    • You can specify a GET method.
  8. After these steps, you will see a confirmation of a successful request to the API Gateway. For more details about the following configurations, click Cool, what’s next?.

Once you have taken a look at the suggested additional configurations, you are ready to use 3scale. Click Got it! Take me to my API on 3scale and you will see the Overview page of your product.

1.3. Initial API configurations to perform test calls

Initial configurations will ensure that your API traffic is protected by API keys, tracked, and monitored by 3scale with basic rate limits and controls in place. If this is the first time you are working with 3scale, you can run the wizard to get assistance configuring your first API.

1.4. Creating backends for your products

A backend is an internal API that is bundled to a product.

Prerequisites

  • You need a 3scale account.

Procedure

  1. Go to the Dashboard.
  2. Under the APIs section, click Create Backend in the Backends card.
  3. Provide the following details:

    • Name: Backend identifier.
    • System name: Identifier used for internal purposes.
    • Description: Optional field containing more details about the backend.
    • Private Base URL: Base URL endpoint of the private API.
  4. Click Create Backend.

After performing the steps for Creating backends for your API, you have an internal API. You can create more backends as needed.

1.5. Creating new products to test API calls

As a 3scale API provider, create products to test API calls through these public APIs. A product is a customer-facing API that packages one or more backends.

You can create a new product by following one of these options:

  • Define the product manually.
  • Import the product from OpenShift.

Here you will find details about the manual definition. If you want to import a product from OpenShift, see Service Discovery.

Prerequisites

  • You need a 3scale account.

Procedure

  1. Go to the Dashboard. Under the APIs section, click Create Product in the Products card.
  2. Provide the following details:

    1. Name: Product identifier.
    2. System name: Identifier used for internal purposes. A product system_name is used to generate proxy endpoints and domain names. By default, system_name is part of a label whose pattern can be as one of the alternatives below:

      • For APIcast staging: %{system_name}-%{tenant_name}-apicast-staging
      • For APIcast production: %{system_name}-%{tenant_name}-apicast-production
      • When an auto-generated URL label exceeds 63 characters, the system shortens the label as follows: <truncated-label>-<unique-hash>

        • <truncated-label> is the first 54 or 55 characters of the original URL.
        • <unique-hash> is the first 7 characters of a unique SHA-1 hash calculated from the original label.

          For example, this is the URL before truncation:

          https://my-very-long-system-name-also-very-long-tenant-name-apicast-staging.3scale.net

          This is the URL after the truncation:

          https://my-very-long-system-name-also-very-long-tenant-name-api-72588d2.3scale.net

    3. Description: Optional field containing more details about the product.
  3. Click Create Product.

After these steps, you have a product that represents the public facing API. The next steps are creating backends and adding them to the product.

1.6. Adding backends to your products

By the end of this procedure you will have added a backend to a product. Repeat the procedure to add more backends as you require them.

Prerequisites

Procedure

  1. Navigate to [Your_product_name] > Integration > Backends.
  2. Click Add Backend.
  3. From the drop down list, perform one of these actions:

    • Select an existing backend.
    • Click View all to see the entire list.

      • If you need to create a new backend, click Create new Backend and complete the details.
  4. Specify the routing path in the Path textbox. For more details, see The backend path of a specific product.
  5. Click Add to Product.
  6. Promote the product under the Products tab in [Your_product_name] > Integration > Configuration.

After these steps, your product will have one backend. You can repeat this procedure to add more backends to a product or to multiple products.

1.7. The backend path of a specific product

When you add a backend to a product, you define the path that the backend uses to communicate with the specified product. This path is not part of the backend.

From the procedure described in Adding backends to your products, APIcast is the API gateway that uses the path of the backend you indicated in step 4. APIcast redirects the traffic to the backend with the specified path matching the prefix of the requested endpoint path.

When defining the path for a backend:

  • You can indicate / as the path of one of the backends.
  • Paths must be unique inside the product. This means that you cannot add two backends with the same path inside the same product. Neither can you add the same backend twice to the same product.
  • You can give the same backend the same path in different products.

This is how the backend path works:

  • Each backend added to a product is mounted in the specified path.
  • Before redirecting the traffic, the path is removed from the public URL of the request to the product.

Example

Consider this configuration to add a backend to a product:

  • Backend: Inventory
  • Resource path: /list
  • Product: Petstore
  • Backend path: /supplies

These are the URLs used by your configuration:

  • Public URL: <public-api-domain>/supplies/list
  • Private URL: <private-api-domain>/list

This is the action flow when a request is sent:

  1. The application sends a request.
  2. The request is sent to the public URL: <public-api-domain>/supplies/list
  3. The backend path is removed before redirecting to the private URL: <private-api-domain>/list
  4. The request is redirected to the Inventory backend.

1.8. Defining mapping rules

A mapping rule associates a call to an endpoint with designated methods and metrics for tracking and limiting access to your API. You can define mapping rules at the backend and product levels. The advantage of defining mapping rules at the backend level is that you can add a backend to multiple products. To learn more about the metrics or methods for which to collect usage information depending on the requests to your API, both at the product and backend levels, see How APIcast applies mapping rules for capturing usage of 3scale APIs.

Prerequisites

Procedure

  1. On the Dashboard, click the Backend you want to define mapping rules for.
  2. In the navigation panel, click Mapping Rules.
  3. Click Create mapping rule.
  4. Specify the following settings:

    • Verb: The HTTP request verb (GET, POST, DELETE, or PUT).
    • Pattern: The pattern to match. For example, /hello.
    • Metric or method to increment: The metric or method name.
    • Increment by: The metric increment number. For example, 1.
    • Last?: If the request matches a rule marked Last?, APIcast stops processing and will not search for matches in the remaining mapping rules, then also stops incrementing their metrics.
    • Position: Number that indicates the position of the execution of the mapping rule, to sort the mapping rules.
  5. Click Create mapping rule.

Next steps

After these steps, the mapping rule is added to Backends under [Your_API_backend] > Mapping Rules. The mapping rule is also available for each product currently using the backend. To have the mapping rule active at the product level, promote the latest configuration under the Products tab in [Your_product_name] > Integration > Configuration.

Example

After you promote the configuration, 3scale activates the backend mapping rules at the product level. The mapping rules follow the backend path specified in the product. For example, suppose you have this configuration:

  • Pattern of the mapping rule at the backend: /thousands
  • Backend is added to a product with path: /unitprice

The mapping rule at the product level is: /unitprice/thousands.

1.9. Creating 3scale application plans for products

A 3scale application plan defines the rules such as limits, pricing, and features for using your API product. For more information, refer to Application plans and Designating methods and adding metrics for capturing usage details.

Prerequisites

Procedure

  1. Navigate to [Your_product_name] > Applications > Application Plans.
  2. Click Create Application Plan.
  3. On the Create Application Plan page, enter a name and a system name for your new plan. A system name must be unique in your 3scale installation.
  4. Click Create Application Plan.

1.10. Creating applications for the default account to test API calls

As a 3scale user, create applications for the default Developer account. An application subscribes to an application plan. As a result of this subscription, 3scale provides the user key required to call an API product.

An application is always associated with an application plan. Applications are stored within developer accounts. In basic 3scale plans only a single application is allowed. In enterprise plans, multiple applications per account are allowed.

Prerequisites

Procedure

  1. Navigate to Audience > Accounts > Listing.
  2. Click the default Developer account.
  3. Click the Applications tab.
  4. Click Create application.
  5. In the Create application dialog, select the product for the application.
  6. Choose an application plan.
  7. Specify an application name.
  8. In the Description field, enter information about this application.
  9. Click Create application.

You can see your new application in Dashboard > Audience > Accounts > Applications > Listing.

1.11. Sending requests to your product to test the integration of a backend

As a 3scale API provider, you can send a command line request to a product to test the integration of a backend based on the first mapping rule added to the product.

Before you can send a test request, you must promote an APIcast configuration that includes the backend that you want to test. A specific APIcast configuration consists of the backends you have added to a product with the corresponding mapping rules, applications, and application plans.

3scale directs requests to the backend of a product according to the path specified in the request call. For each backend of a product, you configured the backend path when you added the backend to the product. In other words, each backend has its own path.

Prerequisites

Procedure

  1. Promote the new APIcast configuration to staging:

    1. Navigate to [Your_product_name] > Integration > Configuration.
    2. Under APIcast Configuration, click Promote v.[n] to Staging APIcast.

      • v.[n] indicates the version number to be promoted.
      • If there are no changes to be promoted, there is a grayed button with the text Nothing to promote.
  2. Under Staging APIcast, promote the APIcast configuration to production by clicking Promote v.[n] to Production APIcast.

    • v.[n] indicates the version number to be promoted.
    • If there are no changes to be promoted, you will see a grayed button with the text Nothing to promote.
  3. To test requests to your API product, copy the command provided in Example curl for testing and run it in a terminal.

    • The curl command example is based on the first mapping rule of the product.
    • After you run the command, you should get an HTML response containing results from the backend you are testing.
    • If you do not get a response, delete the catch-all mapping rule from your product, promote the new APIcast configuration to staging and then to production, and run the example curl command.

Next steps

You can confirm the different responses when changing metrics and methods, such as limits and pricing rules. For any of the application plans of a product, modify the methods and metrics when testing requests to your product. For more details, refer to adding methods and metrics.

Every time you modify the product configuration and before making calls to your API, you must promote the updated configuration to the staging and production environments. When there are pending changes to be promoted to the staging environment, there is an exclamation mark in the Admin Portal, next to the Integration menu item.

1.12. Additional resources

Chapter 2. Launching your APIs

In this chapter, you will learn about some key steps to launch your APIs with Red Hat 3scale API Management. To use this guide, there are these assumptions:

  • 3scale has an internal API called API Backend, which is a backend.
  • 3scale has a customer-facing API called Echo API, which is a product. This is the API that you will expose through the Developer Portal.

The guide covers the following steps to launch your API product:

  1. Secure the product.
  2. Configure the product access policies with application plans.
  3. Engage your developers with a Developer Portal.
  4. Go live.

2.1. Paths to launch your first API

To begin working with 3scale, you can choose one of the three paths to launch and expose your API product. Your API product is the customer-facing API you are showing to the world.

The timing guidelines depend on the complexity of your API product and the resources you plan to dedicate to the effort. You will spend most of your time on refining your API product and preparing content for your Developer Portal. If you already have a stable product and content for documentation, you can go live within a week.

These are the paths to launch your first API product:

Prototype

  • Goal: Complete an end-to-end integration of 3scale with a simple API product, which will be exposed to the public.
  • Recommended for: This path helps you get a general overview of the end-to-end capabilities of 3scale. You must do this path before going through Basic. If you have successfully completed the onboarding wizard in the Admin Portal, you can skip this path and go to the next one.
  • Completion time: Less than an hour.

Basic

  • Goal: Complete all implementation steps to launch your API product in production.
  • Recommended for: If you want to go live with your API product in production and you have limited time, the Basic path will cover most of your needs.
  • Completion time: Less than a week.

Advanced

  • Goal: Optional extras after you have completed the Basic path, such as advanced control of your API product, and deeper customization of the Developer Portal.
  • Recommended for: If you have a more complex requirement or if you have covered the Basic path already, you may be ready to consider advanced options.
  • Completion time: Several weeks.

2.2. Following the Prototype path

You can follow through the Prototype path individually from end to end. Alternatively, you can choose to perform some steps from this path according to your needs. Each path can be independent, but Prototype, Basic, and Advanced paths build on top of each other.

2.2.1. Securing your API

You can prototype the 3scale access control layer within a few minutes, assuming one of the following cases:

  • In 3scale Hosted (SaaS), your product is publicly accessible.
  • In 3scale on-premises, your product is reachable from the 3scale installation.

Echo API serves as an example of a public product. It has the following features:

  • It is a simple API that accepts any path and returns information about the request (path, request parameters, headers, etc.) in the response body.
  • It is accessible at the following URL: https://echo-api.3scale.net
  • The first time you activate 3scale, a product is created for each existing API. In this first time, there is a one-on-one relationship between the product and the API backend. In other words, you will see: Echo API, a product containing API Backend.

To secure your Echo API product, follow these steps:

  1. Verify that your product is reachable. Example: https://echo-api.3scale.net/v1/fast/track

    • After the security layer is in place, you can hide or restrict access to the backend host.
  2. Navigate to [Your_product_name] > Integration > Configuration.
  3. For [Your_product_name], confirm that the private endpoint has been set in the default API Backend. Example: https://echo-api.3scale.net:443
  4. Click the button to promote to staging.
  5. Copy the cURL statement, which includes the user_key as the default credential, to make calls from the command line:

    curl "https://api-2445581407825.staging.apicast.io:443/v1/fast/track?user_key=287d64924e6120d215b1000ac07c063b"

    You can make different calls. For example try another endpoint, adding the same user_key.

    Note

    You can get the API product keys from the application details page, located in one of the developer accounts.

    Your 3scale access control layer will now only allow authenticated calls through to your backend API.

2.2.2. Configuring API access policies with application plans

After following the steps under Section 2.2.1, “Securing your API”, only authenticated calls are allowed through to your APIs. In this section you will apply policies to differentiate the rate limits.

In 3scale, applications define the credentials to access your product. An application is always associated with one application plan that determines the access policies. Applications are stored within developer accounts. In the basic 3scale plans only a single application is allowed; but, in the higher plans, multiple applications per account are allowed.

In this example, you add a policy to the Echo API product used in the preceding section with these steps:

  1. Navigate to [Your_product_name] > Applications > Application Plans.
  2. In the Application plans section, go to the Basic application plan to edit one of the plans that was generated by the sample data after installing or signing up for 3scale.
  3. Under Metrics, Methods, Limits & Pricing Rules, select limits in the hits row, and create a new usage limit of 3 per hour.
  4. Find one of your sample applications, by navigating to [Your_product_name] > Applications > Listing. Ensure that the application is set to the basic plan. If not, change plan on the application details page.
  5. Use the credentials for this application and repeat the previous sample call at least three times.

You have now successfully defined more restrictive access polices for all the applications on 3scale Basic plan.

2.2.3. Engaging developers with a Developer Portal

For the Prototype path, you do not need to create any documentation content. It is usually enough to check that the workflows meet your requirements.

While the product is in development and testing, you can disable the full self-service workflow with these steps:

  1. From your Admin Portal, navigate to the Audience space and click Visit Portal link in the Developer Portal menu.
  2. Create a test signup and walk through all the steps.
  3. Usually self-service is enabled by default. To change it, go to Audience > Accounts > Usage Rules and select the account approval required checkbox.
  4. Repeat the test signup walkthrough and verify that you need to approve the account in the Admin Portal before the user can log in.

You can now successfully customize workflows for your Developer Portal.

2.3. Following the Basic path

You can follow through the Basic path individually from end to end. Alternatively, you can choose to perform some steps from this path according to your needs. Each path can be independent, but Prototype, Basic, and Advanced paths build on top of each other.

2.3.1. Securing your API

For a full production implementation, you need to make some fundamental decisions about how to structure your product and implement integration with 3scale.

You have the choice of several authentication modes for product traffic. Consult the guide on the available options and configure the settings.

Important

After you set the authentication, you should not switch authentication modes because this action might invalidate existing credentials.

Additional resource

Hosted APIcast

  1. Follow the onboarding wizard after you log in to your Admin Portal for the first time.
  2. Continue iterating on your product configuration, such as refining access policies, until you have reached a version suitable for production.
  3. Promote your APIcast configuration to the production gateway.

Self-managed APIcast

  1. Deploy the APIcast gateway self-managed solution using the operator on OpenShift.
  2. Continue iterating on your API configuration, such as refining access policies until you have reached a version suitable for production.
  3. Promote your APIcast configuration to the production gateway.
  4. For further details about self-managed APIcast, see Installing APIcast.

2.3.2. Configuring API access policies with application plans

After following the steps under Section 2.3.1, “Securing your API”, only authenticated calls are allowed through to your product. In this section you will apply policies to differentiate rate limits.

In 3scale, applications define the credentials to access your API product. An application is always associated with one application plan that determines the access policies. Applications are stored within developer accounts. In the basic 3scale plans, only a single application is allowed. In the higher plans, multiple applications per account are allowed.

In Prototype, you can only control access based on overall hits on your product. The flexibility of 3scale is evident after you start using custom methods and metrics to create more sophisticated tiers for your application plans and for deeper analytic insight to your product. For more details, see the analytics guide.

Important
  • The mapping between your API structure and methods or metrics in 3scale is logical. You can get reports of the product usage from 3scale if you define a consistent rule. You must determine the level of detail. Generally, you should aim between 5 and 20 methods/metrics.
  • The values reported to 3scale can only be incremented. You cannot set absolute values or decrease the counters.
  • After adding any new methods or metrics to 3scale, it is important to add the new system names to your integration point.
  • You can make changes, such as rate limits, at runtime without redeploying.

In this example, to add polices to the application plan of the Echo API product, perfom these steps:

  1. Find the product you want to work on.
  2. In the Application Plans section, select basic to edit one of the plans that was generated automatically after signing up to 3scale/deploying your instance.
  3. If you find a rate limit for hits, remove it.
  4. Add a new method to the plan under the hits metric with the system name "test".
  5. Set a rate limit for the test method to 5 per hour.
  6. Add two new metrics with system names v1 and v2.
  7. Under the v2 metric, disable access by clicking on the enabled column. This has the same effect as setting a rate limit of zero.

APIcast deployment

  1. Go to [Your_product_name] > Integration > Configuration.
  2. Expand the mapping rules section and add the following mappings:

    Mapping rules
    Note

    The default mapping for "/" has been removed. If you use this default mapping, it will lead to double-counting of hits.

2.3.3. Engaging developers with a Developer Portal

You can find information to create and provide APIs using the Developer Portal. Consider writing your content in Textile or Markdown. Following are optional steps that you may want to consider:

2.4. Following the Advanced path

You can follow through the Advanced path individually from end to end. Alternatively, you can choose to perform some steps from this path according to your needs. Each path can be independent, but Prototype, Basic, and Advanced paths build on top of each other.

2.4.1. Securing your API

To secure your product, you have the following alternatives:

Advanced authentication mode: OpenID Connect (OIDC)

Secure your products using the APIcast integration with OpenID Connect for Red Hat Single Sign-On (RH-SSO). Applications in 3scale are synchronized with the Identity Provider (IdP), in this case RH-SSO. Currently, this is an end-to-end supported solution. It covers the main OAuth 2.0 flows:

  • Authorization code
  • Resource owner password
  • Client credentials
  • Implicit grant

2.4.2. Configuring API access policies with application plans

With the options listed under Section 2.4.1, “Securing your API”, you ensured that only authenticated calls are allowed through to your product. In this section, you apply policies to differentiate rate limits.

In 3scale, applications define the credentials to access your product. An application is always associated with one application plan that determines the access policies. Applications are stored within developer accounts. In the Basic 3scale plans, only a single application is allowed. In the higher plans, multiple applications per account are allowed.

Alerts may be configured to send notifications by email or to the web consoles:

  1. Go to your API Settings page: [Your_product_name] > Integration > Settings.
  2. Go to the Alerts section on the page. Here, you can configure the alerts that you want as a percentage of your rate limit levels.

3scale gives you the flexibility to decide on the level of rate limits:

  • Soft rate limits: Even calls above the limits are allowed through.
  • Hard rate limits: Calls are rejected before hitting your application.

APIcast defines hard limits by default. These can be customized in the Lua file to avoid rejecting over-limit calls.

2.4.3. Engaging developers with a Developer Portal

After you have completed the Basic path, following are two advanced areas you can explore for the Developer Portal:

  • Liquid markup provides tags and drops that provide direct access to system objects and allow you to introduce dynamic rendering of developer portal pages.
  • All 3scale system pages can be customized. This is for advanced users because the HTML is complex. Ultimately, you can customize virtually any page of your Developer Portal. Usually the default pages will be perfectly fine with some CSS changes.

2.5. Going live

This section describes the final checklist before the public launch of your API product.

Note

Raise request for the custom domain and email as soon as possible because they have a long lead time.

  1. In Audience > Developer Portal > Domains & Access, type a custom domain in the Developer Portal Site field.
  2. Optionally, type a custom outbound email address in the Outgoing Email field.
  3. Remove the Developer Portal access code.
  4. Click Update Account to save changes.

Following are some extra points for consideration:

  • Add pricing to generate earnings directly from your API product. This feature is only available for 3scale Hosted (SaaS) accounts.
  • Use insight from your product analytics, in your Admin Portal located under Analytics, to refine your application plans.

Legal Notice

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.