Nav

API Auto-Discovery Reference

The configuration.xml of a project that includes auto-discovery references one or more global elements in the inbound endpoint. From this endpoint, API Manager obtains the information necessary to register the APIs described by the global elements. The following configuration.xml is an example of an API configured for auto-discovery:


         
      
1
2
3
4
<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>

The api-platform-gw global element contains the information needed to register an API in Anypoint Platform. The global element includes the description and tag attributes. The values you set for these attributes appear on the API version details page after registration:

api-auto-discovery-reference-0dc02

api-platform-gw Attributes

The api-platform-gw attributes include the flowRef attribute. The flowRef attribute replaces the api-ref element that was removed in version 2.0. In an APIkit project, the global element includes an apikitRef that references the global element. The id element is required in API Gateway versions earlier than 2.0.2.

The following table lists the api-platform-gw attributes:

Attribute Required Description

id

No - API Gateway 2.0.2 and later

The bean ID of the element. This value is not propagated to Anypoint Platform.

apiName

Yes

The friendly API name that appears on API Manager and in Studio on Global Element Properties.

version

Yes

The version number. Management breaks if you change the version in API Portal.

flowRef

Yes

A reference to the main flow of your project. It triggers the agent to discover this flow and use it when performing the auto-registration.

apikitRef

No

A reference to the APIkit configuration. Used to upload the RAML file to Anypoint Platform after API registration completes.

create

No

Enables/disables the automatic creation of APIs in the auto-discovery process. If false or not present, the API is still tracked by Anypoint Platform if it already exists. If it doesn’t already exist, the application won’t communicate with the platform. This attribute exists in API Gateway 2.1.0 and later.

api-platform-gw Nested Elements

The following attributes list the api-platform-gw nested elements.

Nested Element Required Description

api-platform-gw:description

No

A description of the API that appears on the API version details page when Anypoint Platform discovers and registers the API.

api-platform-gw:tag

No

The tag is searchable metadata in the API Manager and API that appears on the API version details page when Anypoint Platform discovers and registers the API.

Auto-Discovery in Mule Runtime 3.8.1

The following configuration.xml shows the auto-discovery configuration for two APIs described in the simple REST API tutorial.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/api-platform-gw http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd">
    <http:listener-config name="api-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <apikit:config name="api-config" raml="api.raml" consoleEnabled="false" doc:name="Router"/>
    <http:request-config name="HTTP_Request_Configuration" host="jsonplaceholder.typicode.com" port="80" doc:name="HTTP Request Configuration"/>
    <api-platform-gw:api apiName="apikit-to-api-mgr" version="1.0development" flowRef="api-main" create="true" apikitRef="api-config" doc:name="API Autodiscovery">
        <api-platform-gw:description></api-platform-gw:description>
        <api-platform-gw:tag></api-platform-gw:tag>
    </api-platform-gw:api>
    <flow name="api-main">
        <http:listener config-ref="api-httpListenerConfig" path="/api/*" doc:name="HTTP"/>
        <apikit:router config-ref="api-config" doc:name="APIkit Router"/>
        <exception-strategy ref="api-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
    </flow>
    <flow name="api-console">
        <http:listener config-ref="api-httpListenerConfig" path="/console/*" doc:name="HTTP"/>
        <apikit:console config-ref="api-config" doc:name="APIkit Console"/>
    </flow>
    <flow name="UsersById">
        <http:listener config-ref="api-httpListenerConfig" path="/placeholder/byid" doc:name="HTTP"/>
        <http:request config-ref="HTTP_Request_Configuration" path="/users" method="GET" doc:name="HTTP">
            <http:request-builder>
                <http:query-param paramName="id" value="#[message.inboundProperties.'http.query.params'.id]"/>
            </http:request-builder>
        </http:request>
    </flow>
    <flow name="Users">
        <http:listener config-ref="api-httpListenerConfig" path="/placeholder" allowedMethods="GET" doc:name="HTTP"/>
        <http:request config-ref="HTTP_Request_Configuration" path="/users" method="GET" doc:name="HTTP"/>
    </flow>
    <apikit:mapping-exception-strategy name="api-apiKitGlobalExceptionMapping">
        <apikit:mapping statusCode="404">
            <apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="405">
            <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="415">
            <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="406">
            <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="400">
            <apikit:exception value="org.mule.module.apikit.exception.BadRequestException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
    </apikit:mapping-exception-strategy>
    <flow name="UserNames">
        <http:listener config-ref="api-httpListenerConfig" path="/placeholder/names" allowedMethods="GET" doc:name="Copy_of_HTTP"/>
        <http:request config-ref="HTTP_Request_Configuration" path="/users" method="GET" doc:name="Copy_of_HTTP"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
  payload.name]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>

Auto-Discovery Namespace, Schema, and Dependency Information

Namespace and Schema

mule xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw”
http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd

Auto-Discovery Dependency Information

<dependency>
  <groupId>com.mulesoft.anypoint</groupId>
  <artifactId>mule-module-autodiscovery</artifactId>
  <version>3.8.1</version>
</dependency>