Loading

How to disable APIkit Console in Mulesoft Application

Data pubblicazione: Jul 29, 2025
Fasi

CONTENT

In Studio when you run a RAML-based APIkit project, API Console is generated automatically and gives you access to the generated documentation enables testing the application endpoint as per the specification. The following article discusses auto-generated consoles(for both Mule 3.x and Mule 4.x runtimes) and the ways to disable them.

STEPS TO FOLLOW

SOLUTION -1 

  • One of the ways to disable the Console is by deleting the flow which contains the console element. 
The snippet below shows the "console" flow in Mule 3.x.
<flow name="console">
   <http:listener config-ref="httpListenerConfig" path="/console/*" doc:name="HTTP"/>
   <apikit:console config-ref="config" doc:name="APIkit Console"/>
</flow>
The snippet below shows the "console"  flow in Mule 4.x
<flow name="console">
        <http:listener config-ref="httpListenerConfig" path="/console/*">
            <http:response statusCode="#[vars.httpStatus default 200]">
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:response>
            <http:error-response statusCode="#[vars.httpStatus default 500]">
                <http:body>#[payload]</http:body>
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:error-response>
        </http:listener>
        <apikit:console config-ref="config" />
        <error-handler>
            <on-error-propagate type="APIKIT:NOT_FOUND">
                <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">404</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
        </error-handler>
    </flow>

SOLUTION -2

With source code modification you can allow the application to toggle this functionality through a property placeholder and a choice router:
  • In Mule 3.x the flow would be:
<flow name="api-console">
        <http:listener config-ref="api-httpListenerConfig" path="/console/*" doc:name="HTTP"/>
        <choice doc:name="Choice">
            <when expression="${enableconsole}">
                <apikit:console config-ref="api-config" doc:name="APIkit Console"/>
            </when>
            <otherwise>
                <set-payload value="#[&quot;RESOURCE NOT FOUND&quot;]" mimeType="application/json" doc:name="Set Payload"/>
            </otherwise>
        </choice>
    </flow>
  • In Mule 4, if you are using an APIkit version prior to 1.3.6:
<flow name="hello2-console">
        <http:listener config-ref="hello2-httpListenerConfig" path="/console/*">
            <http:response statusCode="#[vars.httpStatus default 200]">
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:response>
            <http:error-response statusCode="#[vars.httpStatus default 500]">
                <http:body>#[payload]</http:body>
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:error-response>
        </http:listener>
        <choice doc:name="Choice" doc:id="ff456412-25e3-44f4-b42d-6f27dc2916c7" >
			<when expression="${enableConsole}">
				<apikit:console config-ref="hello2-config" />
			</when>
			<otherwise >
				<set-payload value='#["Resource not found"]' doc:name="Set Payload" doc:id="7f05c7dc-6472-408b-a379-c519009b5ea9" mimeType="application/json"/>
			</otherwise>
		</choice>
        <error-handler>
            <on-error-propagate type="APIKIT:NOT_FOUND">
                <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">404</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
        </error-handler>
    </flow>
  • Finally, when running the application the following parameter should be passed to the JVM / Studio VM arguments in order to resolve the placeholder and enable the console "-DenableConsole=true", alternatively in order to disable it, the parameter should be passed as follows "-DenableConsole=false".

SOLUTION -3

  • If you are using APIkit 1.3.6 or a newer one, the following "system property" can be set:
apikit.console.disabled=true

Note 1: This requires system properties and not just a regular app property, so please review the following article to understand how to set it: How can I set Mule and Java system properties at startup?

Note 2:  At the time of documentation[May 13, 2021], The suggested solution is applicable only for the console generate by the APIkit module and not the ones that are created by the proxy application. 

References:
APIkit Console Mule 3.x Overview
APIkit Console Mule 4.x Overview
APIkit Console 1.3.6 Release notes
Numero articolo Knowledge

001117024

 
Caricamento
Salesforce Help | Article