Nav

Proxy Modification Reference

This topic describes the structure of a REST proxy for an API that you can set up in API Manager. The anatomy of a SOAP proxy is similar. From this structure, you can add additional functionality – to log data, for example. 

A proxy abstracts the API to a layer that can be managed by API Manager. A proxy for a REST API should meet the following criteria:

  • Accepts incoming service calls from applications and routes them to the URI of the target API.

  • Copies any message headers from the service call and passes them along to the API.

  • Avoids passing internal Mule headers both to the API and back to the requester. 

  • Captures message headers from the API response and attaches them to the response message.

  • Routes the response to the application that made the service call.

Here’s what a REST proxy might look like in Studio.

proxying-your-api-a2d91

The following example shows an XML configuration of the REST proxy:


    
            
         
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
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw"
        xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
  <api-platform-gw:api id="${api.id}" apiName="${api.name}" version="${api.version}" flowRef="proxy" doc:name="API Autodiscovery">
        <api-platform-gw:description>${api.description}</api-platform-gw:description>
    </api-platform-gw:api>
    <http:request-config name="http-request-config" host="${implementation.host}" port="${implementation.port}" basePath="${implementation.path}" doc:name="HTTP Request Configuration"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="proxy">
        <http:listener config-ref="HTTP_Listener_Configuration" path="${proxy.path}" parseRequest="false" doc:name="HTTP"/>
        <flow-ref name="copy-headers" doc:name="Flow Reference"/>
        <http:request config-ref="http-request-config" method="#[message.inboundProperties['http.method']]"
                      path="#[message.inboundProperties['http.request.path'].substring(message.inboundProperties['http.listener.path'].length()-2)]" parseResponse="false" doc:name="HTTP">
            <http:request-builder>
                <http:query-params expression="#[message.inboundProperties['http.query.params']]"/>
            </http:request-builder>
            <http:success-status-code-validator values="0..599" />
        </http:request>
        <flow-ref name="copy-headers" doc:name="Flow Reference"/>
    </flow>
    <sub-flow name="copy-headers">
        <custom-transformer class="com.mulesoft.gateway.extension.CopyHeadersTransformer" doc:name="Java"/>
        <!-- This can be uncommented for customization
            <copy-properties propertyName="*"/>
            <remove-property propertyName="Host"/>
            <remove-property propertyName="Content-Length"/>
            <remove-property propertyName="MULE_*"/>
            <remove-property propertyName="Connection"/>
            <remove-property propertyName="Transfer-Encoding"/>
            <remove-property propertyName="Server"/>
        -->
    </sub-flow>
</mule>

When importing the proxy for the API into Studio 5.x and earlier, the project is linked to a domain project named api-gateway. Studio 5.x and earlier creates a domain project if necessary. The domain project is identical to the domain that exists in CloudHub and in an API Gateway On-Premises by default. Match the production deployment conditions when deploying an app to the Anypoint Studio 5.x server. If you modify the domain on the API Gateway on-prem installation, replicate the changes on the domain that exists in Studio 5.x or earlier. This domain project contains the <http:listener-config statement that the Mule flow requires.

In the API project, configure the property placeholders in the configuration in the mule-app.properties file, which you can find in the Package Explorer under src/main/app.


         
      
1
2
3
4
5
6
7
8
9
api.id=apiId
api.name=My API
api.version=1.0.0
api.description=This is my API
proxy.path=/api/*
implementation.host=www.google.com
implementation.port=80
implementation.path=/
http.port=8081

If an API requires HTTPS communication as shown in the HTTPS example or returns internal API URLs as part of the response, additional configuration might be required.

The downloaded file is a deployable proxy application. If needed, modify the downloaded zip file to adjust for port conflicts, use shared connector resources, or include custom code for logic that you want to add to the proxy. Deploy the proxy application. After deployment, the yellow circle in the status indicator turns green.

In this topic: