Azure API Management
Azure API Management is a product that allows the developer to wrap their own internal API in order to expose it outside and having a lot of features available without the need to write a line of code.
A typical use case scenario for using this product would be having a lot of legacy code doing useful work and wanting to expose it openly while providing a modern interface.
Create a Product
From Microsoft:
Products are how APIs are surfaced to developers. Products in API Management have one or more APIs, and are configured with a title, description, and terms of use. Products can be Open or Protected. Protected products must be subscribed to before they can be used, while open products can be used without a subscription.
I have created a product called “myawesomeproduct”
Import an Existing API
I just created an API that I will use to play with API Management and that is created straight from the Visual Studio default template.
There is one controller called “ValuesController” and five actions answering at the following URLs:
- GET — https://localhost:44307/api/values
- GET — https://localhost:44307/api/values/1
- POST
- PUT
- DELETE
I have deployed it into an Azure App Service. I will then try to import it from the API Management:
And this created the API:
I can see many boxes, each of them named after an HTTP Verb:
I have the following verbs created by default: DELETE, POST, PATCH, PUT, OPTIONS, HEAD, TRACE.
If I open for example the GET, I will see four boxes:
If I am clicking on the “All Operations” tab and I am looking at the “Inbound processing” box I will find the “set-backend-service” policy pre-configured for me:
But, wait a minute, what is it a policy?
In Azure API Management (APIM), policies are a powerful capability of the system that allow the publisher to change the behavior of the API through configuration. Policies are a collection of Statements that are executed sequentially on the request or response of an API. Popular Statements include format conversion from XML to JSON and call rate limiting to restrict the amount of incoming calls from a developer. Many more policies are available out of the box.
If I am clicking on it this will be the file that will pop over to me:
I can test my new API and this is very simple. It will be sufficient to go on the “Test” tab and add as value the following:
And this will be the result I will get back:
This is what “set-backend-service” does:
Use the
set-backend-service
policy to redirect an incoming request to a different backend than the one specified in the API settings for that operation. This policy changes the backend service base URL of the incoming request to the one specified in the policy.
Conclusions
Azure API Management is a very powerful product that could really have a great impact especially on companies having a lot of legacy code written with interfaces that are hardly usable out of their premises.