Import API using OpenAPI
Instead of importing operations one-by-one, you can also import a full API. The OpenAPI specification (aka Swagger) is a definition format to describe RESTful APIs. The specification creates a RESTful interface for easily developing and consuming an API by effectively mapping all the resources and operations associated with it.
As a demo we will use an API that offers a simple calculator service : Calc API
This is an older API and only available via
HTTP
. Azure API Management provides means for fronting access to it viaHTTPS
, which further demonstrates how Azure API Management can help with a secure, uniform facade while the backend implementation can be reworked and upgraded.
1) On the left menu, open the APIs blade.
2) Click on Add API.
3) Under Create from definition select OpenAPI.
4) Select the Full option in the Create from OpenAPI specification dialog.
5) Enter http://calcapi.cloudapp.net/calcapi.json
as the OpenAPI specification value. You should subsequently see Display name, Name, and Description populate.
Note the intentional use of
http
instead ofhttps
as this backend does not presently supporthttps
.
6) While the backend service only runs on HTTP
, we need to set URL scheme to Both
to allow for Azure API Management ingress to occur on HTTPS for callers such as the Developer Portal.
7) Set the API URL suffix to calc
.
8) Assign Starter and Unlimited products.
9) Press Create.
- Once the API is created, it will show in the list of APIs along with all of its operations.
Ensure that the backend shows as
HTTP
. If that is not the case, navigate to the Settings tab and update the Web service URL accordingly.
- Back in the Developer Portal, try out the Calculator API via the Add two integers GET method, then examine the response.
Accepting the defaults of
49
and51
suffices. There’s presently an issue where defaults are shown in a dropdown. If you wanted to change the values, add newa
andb
parameters and values, then remove the dropdown values.
- Back in the Azure API Management Portal, we can inspect / edit the Open API definition by selecting the Edit icon from the Frontend block:
Troubleshooting
Unable to complete the request
This is likely a mixed-content CORS error in which you are attempting a call to an Azure API Management endpoint that is only set up for HTTP. It fails as the Developer Portal runs on HTTPS. Please check the setup steps above for the URL scheme.