APIM Policy to perform Azure Storage File Shares operations
In Azure API Management, policies are a powerful capability of the system that allow publishers to change the behavior of APIs through configuration. Policies are a collection of Statements that are executed sequentially on the request or response of an API.
Azure APIM policy expressions can also be used to perform operations such as Get, Create, Update and Delete on Azure Storage File Shares. In order to achieve this, we would require an inbound policy in the API operation configuration.
The steps for setting up the same are as below
Steps to add inbound policy to create a file in File Shares –
Go to the API Management Service and select the APIs blade. Then choose the target API from the All APIs list.
This will populate the underlying Operations associated with the chosen API.
For this demo, we are using the sample Echo API which can be imported to your APIM service using the OpenApiSpecification URL linked below:
Select POST (Create Resource) from the API operations list, as highlighted in the screenshot below:
Click on the </> sign to enter Edit mode and insert the new policy like in the below screenshot.
Copy the below policy definition and paste in between the <inbound ></inbound> tags. Update the highlighted values with your Storage account details and save. Please make sure all the required headers are in the same format as below.
4. After saving the policy definition, maneuver to the Test tab of the same API. Select the updated API operation and click on Send. Upon successful authentication, you would receive a 200 OK response and the Ocp-Apim Trace would show a response code 201(Created).
The new created file can be viewed in the File Shares –