In this section, you will learn how to add a REST API to your API Management products and how to expose the API to the developers who are using your API Management service.
We'll use an HTTP-triggered Azure function and, in particular, the Azure function created in Chapter 5, Leveraging the Power of DevOps with Azure Functions.
Just to recap, the Azure function mentioned before is an HTTP-triggered function that can be called using a GET verb and return its version number:
C:\>curl --get https://masterservdevsite.azurewebsites.net/api/GetVersion?code=g5EKQzTFgdXxWXGzH2t...Q==
Your awesome function version 1.1.0.0
You want to add this REST API to your API Management products and, in the next section, you want to add policies to the API (for example, caching or a limit quota):
- On the API Management blade, you must choose the APIs option and, on the right-hand side, you will find various options to add a new API:
- Once you select Function App as the API source, you must select the existing function app:
- Now, you can configure it as follows:
To complete the configuration, you must insert the following:
- Display name: This is the name that will appear in the API documentation. It is mandatory.
- Name: This is the internal name for the API. Again, it is mandatory.
- API URL suffix: This is the suffix that API Management adds to the URL for the API. API Management distinguishes every API by its suffix, so it must be unique for every API you publish.
- Products: This is the list of products the API is linked to. An API can belong to no products (in this case, the API is not visible to developers), or to one or more products.
An API can have more than one REST endpoint. In the previous sample, GetVersionAPI has only the GET verb endpoint.
As soon as you have added the new API to your products, all the developers subscribed to those products will see the new API and will be able to use it.
The new API will also appear in the API list available on the API blade, and you can call it using the curl command:
C:\>curl --get -H "Ocp-Apim-Subscription-Key:e707a6d2b....f86064" https://masterservdevapi.azure-api.net/getversion/GetVersion
Your awesome function version 1.1.0.0
Here, the Ocp-Apim-Subscription-Key header is one of the two subscription keys for the registered user.
You can manage your API by creating a new version directly inside the Azure portal. API Management provides you with a sort of version control system that allows you to expose different versions of the same API (or the same operation inside an API) at the same time.