Before You Begin
This 20-minute tutorial shows you how to add policies to an API and deploy the API in Oracle API Platform Cloud Service.
In this series of tutorials, you learn how to implement APIs. This is the last tutorial in Implementing APIs in Oracle API Platform Cloud Service. Read the tutorials in the order listed.
- Creating a Service Account and Service
- Applying API Policies
Background
In Oracle API Platform Cloud Service, you can apply API policies to secure, limit, and route requests sent to APIs. If the API requests do not meet the API policy criteria you specify, requests to APIs are rejected. A service account contains credentials. Policies using outbound calls or routing, refer to the account to provide the necessary credentials.
In this series of tutorials, you are an API manager working for the NexGen Company and you are given a task of creating service accounts and issuing service grants and applying policies to the Warranty Claims API. In this tutorial, you apply various policies to the Warranty Claims API that helps handle warranty claim tickets.
What Do You Need?
- Completion of the previous tutorial so that you have:
- Created a service account and a service
- Access to the Warranty claim service or any other service as a user with the Manage Service or Reference Service grant
- Access to the Warranty Claim API or any other published API
- An active gateway
Add a Key Validation Policy
Add a key validation policy to allow requests to your API only from registered applications. At runtime, if the key is not present in the given header or query parameter, or if the application is not registered, the request is rejected.
- In the Management Portal navigation menu, click APIs.
- On the APIs page, click the Warranty Claim API.
- Click API Implementation
. - In the Available Policies region, expand Security.
- Hover the mouse pointer over Key Validation, and then click Apply.
Description of the illustration key-validation_apply-api-policy.png - In the Apply Policy dialog, do the following, and click Next
. - Your Policy Name: Enter
Warranty Claim Key Validation. - Comments: Enter
This is the key validation policy for the Warranty Claim API. - Place after the following policy: Select API Request.
- Your Policy Name: Enter
- On the next screen of the Apply Policy dialog, do the following, and then click Apply:
- Key Delivery Approach: Select Query Parameter.
- Key Query Parameter: Enter
WarrantyClaim.
- On the Warranty Claim API page, click Save.
The Request tab lists the Key Validation policy for the API.
Add an API Rate Limiting Policy
Use an API rate limiting policy to limit the total number of requests your API allows in a specified period. You can specify the period in seconds, minutes, hours, days, weeks, or months.
- In the Available Policies region of the Warranty Claim API, expand Traffic Management.
- Hover the mouse pointer over API Rate Limiting, and then click Apply.
- In the Apply Policy dialog, do the following, and then click Next
. - Your Policy Name: Enter
Warranty Claim API Rate Limiting. - Comments: Enter
This is the API rate limiting policy for the Warranty Claim API. - Place after the following policy: Select Warranty Claim Key Validation.
- Your Policy Name: Enter
- On the next screen of the Apply Policy dialog, do the following, and then click Apply:
- Allow API Rate Limiting: Select per Logical Gateway.
- API Rate Limit: Enter
100. - Time Interval: Select Second.
- On the Warranty Claim API page, click Save.
The Request tab lists the API Rate Limiting policy for the API.
Add a Resource-Based Routing Policy
Use the Resource-based routing policy to route requests to specific resource paths to different service request URLs.
- In the Available Policies region of the Warranty Claim API, expand Routing.
- Hover the mouse pointer over Resource Based Routing, and then click Apply.
- In the Apply Policy dialog, do the following, and then click Next
. - Your Policy Name: Enter
Warranty Claim Resource Based Routing. - Comments: Enter
This is the resource based routing policy for the Warranty Claim API. - Place after the following policy: Select Warranty Claim API Rate Limiting.
- Your Policy Name: Enter
- Under Resource Configuration, enter the resource path as
/warrantyclaim. - In the Service section, select Select Existing, then click Select Service.
- Select Warranty claim service as a service, and then click Select.
- In the Otherwise section, select Keep Default Service Request.
- Click Apply.
- On the Warranty Claim API page, click Save.
The resource path field does not appear when the API does not have Apiary Specification. If the resource path field does not appear, select Manual under Resource Paths, click Select Resources, then enter the resource path as /warrantyclaim.
The Request tab lists the Resource Based Routing policy for the API.
Add a Header Validation Policy
Add a header validation policy to pass or reject requests based on the condition specified for headers.
- In the Available Policies region of the Warranty Claim API, expand Interface Management.
- Hover the mouse over Header Validation, and then click Apply.
- In the Apply Policy dialog, do the following, and then click Next
. - Your Policy Name: Enter
Warranty Claim Header Validation. - Comments: Enter
This is the header validation policy for the Warranty Claim API. - Place after the following policy: Select Warranty Claim Key Validation.
- Your Policy Name: Enter
- Select the following to set a policy to pass request if all header conditions are met:
- From the first drop-down list, select Pass.
- From the second drop-down list, select All.
- Enter the following to set the header condition as
warranty years <=5years.- Name: Enter
warranty years. - Operator: Select <=.
- Value: Enter
5.
- Name: Enter
- Click Add a new condition
, and enter the following to set the header condition as amount <=1000.
- Name: Enter
amount. - Operator: Select <=.
- Value: Enter
1000.
Description of the illustration header-validation_apply-api-policy.png - Name: Enter
- Click Apply.
- On the Warranty Claim API page, click Save.
The Request tab lists Header Validation policy along with other policies for the API.
Description of the illustration all-policies_apply-api-policy.png
Deploy the API
Deploy the endpoint for your API to a gateway.
- In the navigation pane of the Warranty Claim API page, click Deployments
. - On the Deployments page, click Deploy API.
- In the Deploy API dialog, select Production Gateway to deploy the API.
- For Initial Deployment State, select Active.
- Click Deploy.
The Warranty Claim API is deployed.
Want to Learn More?
- Managing Services and Service Accounts in Using Oracle Autonomous API Platform Cloud Service
- Implementing APIs in Using Oracle Autonomous API Platform Cloud Service
- Deploying Endpoints in Using Oracle Autonomous API Platform Cloud Service
Applying API Policies