Policy Management

Policies are applied to an API Proxy to customize its behavior. These are preprocessing steps which are run on the SAP API Management layer and not on backend services.

Policies can be broadly classified into following four categories:

  • Traffic Management Policies
  • Mediation Policies
  • Security Policies
  • Custom Policies

Traffic Management Policies

The traffic management policies let us configure cache, control traffic quotas and spikes, set concurrent rate limits. Example of these types of policies are:

  • Cache Policies
  • Concurrent Rate Limit Policy
  • Quota Policy
  • Spike Arrest Policy

Mediation Policies

These policies let us perform message transformation, parsing, validation and raise faults and alerts. Examples include the following policies:

  • XSL Transformation Policy
  • XML to JSON Policy
  • Fault Rule Policy
  • Key value Map Operations Policy
  • JSON to XML Policy
  • Assign Message Policy
  • Access Entity Policy
  • Extract variables Policy

Security Policies

These policies controls the security related aspects for API Proxies. Examples include:

  • Access Control Policy
  • Basic Authentication Policy
  • JSON Threat Protection Policy
  • OAuth Policy
  • Verify API Key Policy

Custom Policies

These policies let us provide custom policy functionality, with support for features as service callout, message data collection, and calling Java, JavaScript and created Python behavior. Examples include:

  • Java Script Policy
  • Message Logging Policy
  • Statistics Collector Policy

How Policies Work?

When a policy is added to an API Proxy, then it is added to a specific flow which defines when the policy is executed. Each request and response path in a proxy endpoint and target endpoint defines the following flows:

  • Pre Flow
    • Always executes before any other flows.
    • The policies defined in the pre flow are applied to every message that passes through an endpoint.
  • Conditional Flows
    • Execute only when a conditional statement defined for the Flow evaluates to true.
    • An endpoint can define any number of conditional Flows, but only the first conditional Flow whose condition evaluates to true executes. That means the policies attached to the conditional Flow only execute when the conditional Flow executes.
  • Post Flow
    • Always executes after all other Flows.
    • Like Pre Flow, the policies defined in the Post Flow are applied to every message.

Add first policy: Verify API Key Policy

Let’s add a policy to an API Proxy.

  • To start with, login to SAP API Management’s API Portal.
  • Create an API Proxy from API Portal, [refer here for more details].
  • To add the Verify API Key Policy, following the steps mentioned below:

Click on Launch Policy Designer

1.JPG

Click on PreFlow (in left panel) and then click on Verify API Key among the list of policies (on right side panel).

2.JPG

Just add the policy name and click Add.

3.JPG

Then, the policy will get added & then add the following text in the script area:

<VerifyAPIKey async=’true’ continueOnError=’false’ enabled=’true’ xmlns=’http://www.sap.com/apimgmt‘>

            <APIKey ref=’request.header.apikey‘/>

</VerifyAPIKey>

Then update the policy by clicking Update.

  • The APIKey ref is the key which is used while consuming this API.
  • Since, the key is saved as request header, so the while consuming, this key is to be passed as request header.
  • Refer here for more details.

4.JPG

Then the API Proxy will be updated with newly added policy; and then Click Save.

/wp-content/uploads/2016/02/5_891004.jpg

The API Proxy will be updated successfully.

/wp-content/uploads/2016/02/6_891008.jpg

Create a Product having this API Proxy

Create a product, adding this newly created API (“CATALOGSERVICE”). Refer here for more details.

7.JPG

Publish this product

/wp-content/uploads/2016/02/8_891010.jpg

Consuming the API

To consume the API via product, we need to now login to the developer portal. Once logged in, we will find the newly published API Product here.

9.JPG

Then, an application has to be created using this Product. Refer here for more details.

Open the details of this product and subscribe it to a new application; as shown below:

10.JPG

Enter application details like name, description and click save to create the application. Once created successfully, you will get an appkey and secret for that application.

11.JPG

Testing the API using Verify API Key Policy

  • To test the API, we will be using the SAP API Management’s Test Console. Refer here for more details.
  • Add the proper URl and Authentication (if any) in the Test Cosole.
  • Add the appkey (which was retrieved while creating application) as the Header and click Send to get the result.

14.JPG

This is how you can create an API proxy with Verify API Key Policy and consume the same.

Related Content

SAP API Management Online Guide

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Debtirtha Das

    Thanks for the nice blog Vanu. One question, is it possible to send message asynchronously in API M? is there any way we can stop the post flow?

    (0) 

Leave a Reply