SAP API Management – simplify your life with policy templates!
If you have been using SAP API Management for a while, you may have setup your own little library of policies that you re-use on a regular basis. For instance, you may want to apply the same exact “Verify API key” policy on each one of your API proxies. Or you want to precisely format the XML response of your backend into a specific JSON format, using the “XMLtoJSON” policy. Or you have a set of policies that will do token mediation.
In order to simplify your life, SAP API Management now allows users to store a set of policies as templates.
That means that you can define, within SAP Management itself, a set of policies that can be re-used by you and your peers. Instead of manually creating each policy, you simply import the set of pre-configured policies into your API proxy. These policies will then automatically placed in the response or request of your existing API proxy. Note that you can also chose which policies you want to use.
In this blog, I will show this feature in a little more detail.
Step 1: create your Policy Template
Whether you already have created your policies in an API Proxy, or want to start from scratch: you will need to define the policies in an API Proxy.
In our case, I will re-use an API Proxy. In that proxy, I have a “Verify API Key” and “Response cache” policy that I would like to store as template. The “response cache” policy is a good example, since you always need to position this policy twice in the the pipeline (once in the request, once in the response): using it in a template will simplify its usage.
In the “Policies” screen, you now have the “Policy Template” option. If you are in read-mode, you will be able to “Create” a Policy Template.
When you click the “Create” button, you will be able to chose the policies you want to have in your template.
In my case, I only chose “ResponseCache” and “VerifyAPIKey”, and click on “Create”.
Step 2: Manage your policy templates
Once you have created your policy template(s), you can manage them. To do so, click on the “Develop” menu.
From the main screen, you can now select the “Policy Templates” menu.
Here you can see the template you have just created.
Clicking on the action button on the right lets you export the template or delete it.
The export function can be very useful to copy your policy template across different SAP API Management environments for instance.
Step 3: Using template policies
Once you have defined a template policy, it is very easy to use it.
Simply open the API Proxy “Policy Editor” in which you want to insert the policies. Now you need to switch to the “Edit” mode by clicking on “Edit”.
When clicking on “Policy Template”, you can now chose to “apply” a template.
In the “Apply Template” window that shows up, you can now select the Policy Template that was just created.
If you want, you can expand the policy template, and chose only the policies you are interested in.
For importing the policies int your API Proxy, you have 2 possibilities: either “Copy only”, or “Apply”.
Selecting “Copy only” will only add the policies into the pool of policies for you to place where you want on the pipeline (response or request).
Selecting “Apply” will add the policies to the pool of available policies, but also position them in the request and response pipeline.
In my example, I chose the “Apply” method:
Note that resources such as XSL or JS files are also copied over when using a policy template.
With the “Policy Template” feature, SAP API Management makes you even more efficient and agile when creating API Proxies!