<api-platform-gw:api apiName="Q3 API" version="1.0development" flowRef="api-main" create="true" apikitRef="api-config" doc:name="API Autodiscovery">
<api-platform-gw:description>Consume site statistics and perform Q3 computations</api-platform-gw:description>
<api-platform-gw:tag>Q3results</api-platform-gw:tag>
</api-platform-gw:api>
To Configure Autodiscovery
You include API Autodiscovery capability in a Mule application to enable API management from Anypoint Platform on the application HTTP endpoint. Include code in your Mule app, or use Studio to incorporate Autodiscovery in your project.
The following configuration.xml shows code that configures Autodiscovery:
For more information about the elements, see the Autodiscovery reference link below.
Studio Configuration
To use API Autodiscovery, first you need to pair Anypoint Studio with an Anypoint Platform organization by adding organization credentials to Studio Preferences. Next, you configure Autodiscovery for each flow you want to manage using a global element. A Global Element contains the necessary information for registering an API to Anypoint Platform. Global Elements must then be referenced by one or more endpoints. Finally, you deploy the API project as a Mule application in Studio. API Manager discovers the API and registers it. The API appears on the API Administration page in Anypoint Platform for each flow you configure for Autodiscovery.
To configure and trigger Autodiscovery:
-
In a browser, log in to Anypoint Platform as an administrator, click Access Management. Select Organization.
Select your Organization from the list.
The client ID and client secret appear.
-
From the Anypoint Studio main menu, select Anypoint Studio > Preferences > Anypoint Studio > Anypoint Platform for APIs.
The Preferences dialog for Anypoint Platform for APIs appears.
-
Copy the client ID and client secret from step 2 to Client Credentials.
This action pairs Mule Runtime with your Anypoint Platform organization.
-
Click Validate to verify that the pairing succeeds.
-
Click OK.
-
In Project Explorer, select the app. For example, select
api.xml
insrc/main/app
that you created in the APIkit tutorial. -
On the Global Elements tab on the canvas, click Create.
The Choose Global Type dialog appears.
-
Select Component configurations > API Autodiscovery.
The Global Element Properties - API Autodiscovery dialog appears.
-
Create a global element to declare the details of the API version you want Anypoint Platform to discover:
-
In API Name, type an arbitrary name, for example
vending
.If you are creating a new API, API Manager makes this name visible in Anypoint Platform.
-
In API Version, type an arbitrary version identifier, for example
1.0development
.Do not change the version name later in API Portal, as explained in "Best Practices".
-
In Flow Name, select the name of the flow in the API from the drop-down. Select the flow that you want to which you want to direct requests. For example, select
api-main
, the APIkit tutorial main flow. -
Check the option to automatically create an API if it doesn’t exist.
-
In APIkit Router Configuration, click api-config from the drop-down in the case of the APIkit tutorial.
This configuration is not used by API Manager.
-
In Description, write some documentation about the API.
-
Click OK.
-
-
In Project Explorer, right-click the app,
api.xml
in this example, and select Run As > Mule Application.In a few moments, the API appears on the API Administration page of Anypoint Platform.
You need to be a member of the Organization Administrators or API Versions Owner role to see a newly registered API in Anypoint Platform.
Autodiscovery on CloudHub
If you use the Deploy to Anypoint Platform > Cloud context menu to deploy an API or proxy with Autodiscovery to Anypoint Platform, CloudHub automatically replaces 0.0.0.0
:${http.port} in your endpoint with <YourUniqueDomain>.cloudhub.io and sends this endpoint URL to the API Manager to be displayed and tracked by the agent.
If your endpoint runs over HTTP, use the variable http.port
in its address. If the endpoint runs over HTTPS, use the variable https.port
instead.
Configuring and Using Autodiscovery - API Gateway Runtime 2.x
To set up an API for Autodiscovery, you first install an API Gateway Runtime in Studio. For example, install API Gateway Runtime 2.2.0. Next, follow the procedure in the previous section to configure and use Autodiscovery.
Best Practices
Perform the following tasks after using Autodiscovery to deploy an API:
-
API Autodiscovery registers new APIs, API versions, and/or endpoints. If the API already exists, the agent does not compare the name, description, tags, or any other information contained in the global element for updates.
-
After you have registered new APIs or versions using Autodiscovery, visit Anypoint Platform and add the necessary API Versions Owner permissions so that users who need to access the API version details page for this API version can get there.
-
Set the endpoint host to
0.0.0.0
instead of localhost. -
Do not change the API Version name in API Portal if you have used Autodiscovery. Doing so will break management of the API/
Configure a production API Gateway for integration with Anypoint Platform. For more information, see the link below for configuring API Gateway.