Import and configure an API with Azure API Management

Code VelocityCode Velocity
2 min read

In this article, we will create an Azure API Management instance, import an OpenAPI specification backend API, configure the API settings including the web service URL and subscription requirements, and test the API operations to verify they work correctly.

Create an API Management instance

Navigate to portal.azure.com and sign in with your Azure credentials.

Click the [>_] button > select No storage account required > your subscription > Apply

Create a resource group

az group create --location swedencentral --name myResourceGroup

Here instead of swedencentral, you can use eastus or eastus2 or any location you want. Instead of myResourceGroup, you can use any name you desire.

Replace myLocation with the value you chose earlier. The APIM name needs to be a globally unique name, and the following script generates a random string. Replace myEmail with an email address you can access.

myApiName=import-apim-$RANDOM
myLocation=swedencentral
myEmail=myEmail

Create an APIM instance. The az apim create command is used to create the instance. Replace myResourceGroup with the value you chose earlier.

az apim create -n $myApiName \
    --location $myLocation \
    --publisher-email $myEmail  \
    --resource-group myResourceGroup \
    --publisher-name Import-API-Exercise \
    --sku-name Consumption

It might take a few minutes.

Import a backend API

Search for and select API Management services on Azure portal**.**

On the API Management services screen, select the API Management instance you created from earlier step.

In the API management service navigation pane, select > APIs and then select APIs.

Select OpenAPI in the Create from definition section, and set the Basic/Full toggle to Full in the pop-up that appears.

Create.

Configure the API settings

The Big Conference API is created. Now it's time to configure the API settings.

  1. Select Settings in menu.

  2. Enter https://bigconference.azurewebsites.net/ in the Web service URL field.

  3. Deselect the Subscription required checkbox.

  4. Select Save.

Test the API

Now that the API has been imported and configured it's time to test the API.

  1. Select Test in the menu bar. This will display all of the operations available in the API.

  2. Search for, and select the Speakers_Get operation.

  3. Select Send. You may need to scroll down on the page to view the HTTP response.

    Backend responds with 200 OK and some data.

Clean up resources

Now that we finished the exercise, we should delete the cloud resources we created to avoid unnecessary resource usage. Go to Resource group and delete it.

References

https://microsoftlearning.github.io/mslearn-azure-developer/instructions/azure-api-mgmt/01-api-mgmt-import-api.html

0
Subscribe to my newsletter

Read articles from Code Velocity directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Code Velocity
Code Velocity

Have dual bachelor degrees in BSc in Control Engineering and Computer Engineering and MSc in Artificial Intelligence. Have worked as .net fullstack/ backend developer almost 5 years now. Passionate about both Software and AI Engineering. Specializing in Azure Cloud currently.