Oracle API Platform Cloud Service: Configuring Rate-Limiting, Header Validation, and Resource-Based Routing Policies


Options



Before You Begin

Purpose

This tutorial shows you how to configure rate-limiting, header validation, and resource-based routing policies in Oracle API Platform Cloud Service.

Time to Complete

45 minutes

Background

Oracle API Platform Cloud Service abstracts the complexity of your implementations and provides simpler interfaces so that you can easily protect your APIs. You can use the Management Portal of the Oracle API Platform Cloud Service to configure and apply as many policies as you need. For example, you can restrict the requests per minute that an API can handle, or narrow the access to a certain audience.

Scenario

Multiple requests are arriving every minute, which affects the performance of the Energy API. The development team is working on a solution to improve the performance, but until a solution is in place, they must limit the number of requests arriving per minute. To receive a response from the API, every request must include a custom header; otherwise, the request will be rejected.

Context

This is the seventh tutorial in a series of nine. This tutorial shows you how to configure rate-limiting, header validation, and resource-based routing policies for your APIs in Oracle API Platform Cloud Service. In previous tutorials, you learned how to implement and deploy the Energy API in Oracle API Platform Cloud Service.

What Do You Need?

Logging In to the Portal

Learn how to log in to the API Platform Cloud Service Management Portal and how to navigate to the Energy API page.

  1. From a web browser, go to the API Platform Cloud Service Management Portal by entering the URL in this format:

    http://hostname.domain:port/apiplatform
  2. On the API Platform Cloud Management Portal login page, enter your user name and password, and then click Sign In.

    API Platform Cloud Service Management Portal page
    Description of this image
  3. On the APIs page, click Energy.

    Energy 1 API
    Description of this image

Configuring a Traffic Management Policy

Adding an API Rate Limiting Policy

You can use an API Rate Limiting policy to control how many requests are routed to the Energy API during a given period of time.

  1. On the API Implementation tab of the Energy API page, in the Available Policies panel, expand Traffic Management, hold the cursor over API Rate Limiting, and click Apply.

    Available Policies panel
    Description of this image
  2. On the Apply Policy page, click Next.

    Apply Policy page
    Description of this image
  3. On the Apply Policy page, enter 3 in the API Rate Limit field, select Minute from the Time Interval list, and then click Apply.

    Apply Policy page
    Description of this image

    The API Rate Limiting policy appears on the Request tab of the API Implementation panel.

    API Implementation page
    Description of this image
  4. On the APIs page, click Save Changes.

    Save Changes
    Description of this image

Redeploying the API After Adding the API Rate-Limiting Policy

After you add the API rate-limiting policy to the Energy API, you must redeploy the API to activate the policy.

  1. On the Deployments tab, hold the cursor over the gateway name where the API is deployed, and then click Redeploy.

    Deployments page
    Description of this image
  2. On the Redeploy menu, click Latest Iteration.

    Production gateway panel
    Description of this image
  3. On the Deployment page, enter a comment about the reason to redeploy, and click Yes.

    Confirmation message for redeployment
    Description of this image
  4. On the Deployments tab, wait until the deployment is complete before testing your API.

    Deployments page
    Description of this image

    Note: If the deployment isn't moved from the Waiting tab to the Deployed tab, then try refreshing the page.

    The Waiting tab is automatically updated when the API is deployed, and the date is updated with a new deployment date.

    Deployments page
    Description of this image

Testing the API Rate-Limiting Policy

After the redeployment is complete, the API applies the API rate-limiting policy to the incoming requests.

  1. Build your API URL using this format:

    http://hostname.domain:port/api_endpoint_url/resource_path
  2. Open the Postman client, select the GET method, enter the API URL, and then click Send.

    Postman client
    Description of this image
  3. Repeat Step 2 more than three times in less than a minute to trigger the API rate-limiting policy.

  4. On the Body tab, verify that after the third execution, the API rate-limiting policy is triggered.

    Body tab with API response
    Description of this image

Configuring an Interface Management Policy

Adding a Header Validation Policy

Header validation policies are used to enforce the presence of values in the HTTP headers of the incoming requests. You use them to determine the API behavior by choosing the options to either reject or pass the requests under certain conditions.

  1. On the API Implementation tab of the Energy API page, in the Available Policies panel, expand Interface Management, hold the cursor over Header Validation, and click Apply.

    Available Policies panel
    Description of this image
  2. On the Apply Policy page, select API Rate Limiting from the Place after the following policy list, and then click Next.

    Apply Policy page
    Description of this image
  3. On the Apply Policy page, enter or select the following values, and then click Apply:

    • Action: PASS
    • Conditions: ANY
    • Name: tenant-id
    • Operator: >=
    • Value: 1
    Apply Policy page
    Description of this image

    The Header Validation policy appears on the Request tab of the API Implementation panel.

    API Implementation page
    Description of this image
  4. On the APIs page, click Save Changes.

    Save Changes
    Description of this image

Redeploying the API After Adding the Header Validation Policy

After you add the header validation policy to the Energy API, you must redeploy the API to activate the policy.

  1. On the Deployments tab, hold the cursor over the gateway name where the API is deployed, and then click Redeploy.

    Deployments page
    Description of this image
  2. On the Redeploy menu, click Latest Iteration.

    Production gateway panel
    Description of this image
  3. On the Deployment page, enter a comment about the reason to redeploy, and click Yes.

    Confirmation message for redeployment
    Description of this image
  4. On the Deployments tab, wait until the deployment is complete before testing your API.

    Deployments page
    Description of this image

    Note: If the deployment isn't moved from the Waiting tab to the Deployed tab, then try refreshing the page.

    The Waiting tab is automatically updated when the API is deployed, and the date is updated with a new deployment date.

    Deployments page
    Description of this image

Testing the Header Validation Policy

After the redeployment is complete, the API applies the header validation policy to the incoming requests.

  1. Build your API URL using this format:

    http://hostname.domain:port/api_endpoint_url/resource_path
  2. Open the Postman client, select the GET method, enter the API URL, and then click Send.

    Postman client
    Description of this image

    The API response displays an error message because the header validation policy didn't find the required header values.

    Body tab with API response
    Description of this image
  3. In the Postman client, enter tenant-id in the key field, enter 0 in the value field, and then click Send.

    Postman client
    Description of this image

    The API response displays an error message because the header validation policy didn't allow the request with the sent header values.

    Body tab with API response
    Description of this image
  4. In the Postman client, enter tenant-id in the key field, enter 1 in the value field, and then click Send.

    Postman client
    Description of this image

    The API response displays the expected result in JSON format.

    Body tab with API response
    Description of this image

Configuring a Routing Policy

Adding a Resource-Based Routing Policy

Resource-based routing policies are used to route the incoming requests to specific resource paths to different service response URLs. This policy allows you to combine two back-end services that return different implementation results.

  1. On the API Implementation tab of the Energy API page, in the Available Policies panel, expand Routing, hold the cursor over Resource Based Routing, and click Apply.

    Available policies panel
    Description of this image
  2. On the Apply Policy page, select Header Validation from the Place after the following policy list, and then click Next.

    Apply Policy page
    Description of this image
  3. On the Apply Policy page, enter or select the following values, and then click Apply:

    • Resource Path(s): *estimate*
    • Set Service Request URL To: your_own_estimate_api_implementation
    • Otherwise: Keep Default Service Request URL
    Apply Policy page
    Description of this image

    Note: If you don't have your own implementation of the estimate API, then use this service request URL as an example: http://private-333802-estimate.apiary-mock.com.

    The resource-based routing policy appears on the Request tab of the API Implementation panel.

    API Implementation page
    Description of this image
  4. On the APIs page, click Save Changes.

    Save Changes
    Description of this image

Redeploying the API After Adding the Resource-Based Routing Policy

After you add the resource-based routing policy to the Energy API, you must redeploy the API to activate the policy.

  1. On the Deployments tab, hold the cursor over the gateway name where the API is deployed, and then click Redeploy.

    Deployments page
    Description of this image
  2. On the Redeploy menu, click Latest Iteration.

    Production gateway panel
    Description of this image
  3. On the Deployment page, enter a comment about the reason to redeploy, and click Yes.

    Confirmation message for redeployment
    Description of this image
  4. On the Deployments tab, wait until the deployment is complete before testing your API.

    Deployments page
    Description of this image

    Note: If the deployment isn't moved from the Waiting tab to the Deployed tab, then try refreshing the page.

    The Waiting tab is automatically updated when the API is deployed, and the date is updated with a new deployment date.

    Deployments page
    Description of this image

Testing the Resource-Based Routing Policy

After the redeployment is complete, the API applies the resource-based routing policy to the incoming requests.

  1. Build your API URL using this format:

    http://hostname.domain:port/api_endpoint_url/resource_path
  2. Open the Postman client, select the GET method, enter the estimate API URL, and then click Send.

    Postman client
    Description of this image

    Note: The URL must point to the estimate API, and the tenant-id key/value pair must be included if the header validation policy is still applied.

  3. On the Body tab, verify that the response is from the estimate API.

    Body tab with API response
    Description of this image

Want to Learn More?