---
schema_version: "1"
id: 101c1116ca1401f7e60efaf4a4b04c159a5e43aa65e39e78b39a9aa7485b3014
title: HTTP Connector XML Reference
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/http-connector/latest/http-connector-xml-reference.md
canonical_url: https://docs.mulesoft.com/http-connector/latest/http-connector-xml-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ae34bf6a3bbefc5da08968019402a389a9b9a77c18f50a6abddaa18e9398829f
description: MuleSoft Documentation Site
release: "1.12"
latest: true
---
---
product: HTTP Connector
version: 1.12
is-latest-version: true
keywords: connectors, http, https, configuration
---

# HTTP Connector XML Reference

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Anypoint Connector for HTTP (HTTP Connector) listens for events or performs operations based on the
HTTP or HTTPS protocol. When using the HTTPS protocol, the connector requires a TLS context child
element configuration. The following examples show HTTP Connector source and operations
configuration in XML.

## HTTP Listener XML Configuration Example

The `http:listener-config` parent element organizes connection elements, such as the listen `port`
and `tls:context`, inside a child `http:listener-connection` element. The following example shows
the XML configuration:

```xml
<http:listener-config name="lisConfig" basePath="api">
  <http:listener-connection protocol="https" port="${serverPort}" host="localhost" usePersistentConnections="true">
    <tls:context>
      <tls:key-store path="keystore.jks" keyPassword="key" password="pass"/>
    </tls:context>
  </http:listener-connection>
</http:listener-config>
```

The following example shows the XML configuration of an `http:listener` source in a flow:

```xml
<flow name="server">
  <http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
  <logger message="HEY"/>
</flow>
```

To access HTTP listener attributes, use DataWeave syntax as shown in the following table:

<table><colgroup><col> <col></colgroup><thead><tr><th>HTTP object</th><th>Mule runtime engine 4.x</th></tr></thead><tbody><tr><td><div><div><p>Method</p></div></div></td><td><div><div><p><code>#[attributes.method]</code></p></div></div></td></tr><tr><td><div><div><p>Path</p></div></div></td><td><div><div><p><code>#[attributes.listenerPath]</code></p></div></div></td></tr><tr><td><div><div><p>Relative Path</p></div></div></td><td><div><div><p><code>#[attributes.relativePath]</code></p></div></div></td></tr><tr><td><div><div><p>Request URI</p></div></div></td><td><div><div><p><code>#[attributes.requestUri]</code></p></div></div></td></tr><tr><td><div><div><p>Query String</p></div></div></td><td><div><div><p><code>#[attributes.queryString]</code></p></div></div></td></tr><tr><td><div><div><p>Query Parameters</p></div></div></td><td><div><div><p><code>#[attributes.queryParams]</code></p></div></div></td></tr><tr><td><div><div><p>URI Parameters</p></div></div></td><td><div><div><p><code>#[attributes.uriParams]</code></p></div></div></td></tr><tr><td><div><div><p>Version</p></div></div></td><td><div><div><p><code>#[attributes.version]</code></p></div></div></td></tr><tr><td><div><div><p>Scheme</p></div></div></td><td><div><div><p><code>#[attributes.scheme]</code></p></div></div></td></tr><tr><td><div><div><p>Headers</p></div></div></td><td><div><div><p><code>#[attributes.headers]</code></p></div></div></td></tr><tr><td><div><div><p>Remote Address</p></div></div></td><td><div><div><p><code>#[attributes.remoteAddress]</code></p></div></div></td></tr><tr><td><div><div><p>Client Certificate</p></div></div></td><td><div><div><p><code>#[attributes.clientCertificate]</code></p></div></div></td></tr></tbody></table>

## HTTP Request XML Configuration Example

The `http:request-config` parent element organizes connection elements of the request inside a child
`http:request-connection` element. The following example shows the XML configuration:

```xml
<http:request-config name="reqConfig" basePath="api/v2">
  <http:request-connection protocol="HTTP" port="${clientPort}" host="localhost">
    <tls:context>
      <tls:trust-store path="ssltest-cacerts.jks" password="changeit"/>
    </tls:context>
    <http:authentication>
      <http:basic-authentication username="#[user]" password="#[password]" preemptive="#[preemptive]" />
    </http:authentication>
  </http:request-connection>
</http:requester-config>
```

The following example shows the XML configuration of an `http:request` operation in a flow:

```xml
<flow name="client">
   <http:request path="/" config-ref="reqConfig"/>
</flow>
```

The HTTP request returns `HttpResponseAttributes`. To access HTTP request attributes, use DataWeave
syntax as shown in the following table:

<table><colgroup><col> <col></colgroup><thead><tr><th>HTTP object</th><th>Mule runtime engine 4.x</th></tr></thead><tbody><tr><td><div><div><p>Status Code</p></div></div></td><td><div><div><p><code>#[attributes.statusCode]</code></p></div></div></td></tr><tr><td><div><div><p>Reason Phrase</p></div></div></td><td><div><div><p><code>#[attributes.reasonPhrase]</code></p></div></div></td></tr><tr><td><div><div><p>Headers</p></div></div></td><td><div><div><p><code>#[attributes.headers]</code></p></div></div></td></tr></tbody></table>

## HTTP Load Static Resource XML Configuration Example

The following example shows the XML configuration of an `http:load-static-resource` operation in a
flow:

```xml
<flow name="server">
   <http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
   <http:load-static-resource resourceBasePath="root" defaultFile="index.html"/>
</flow>
```

## HTTP Basic Security Filter XML Configuration Example

The following example shows the XML configuration of an `http:basic-security-filter` operation in a
flow:

```xml
<flow name="listenerBasicAuth">
   <http:listener config-ref="listenerConfigBasicAuth" path="/basic"/>
   <http:basic-security-filter realm="mule-realm"/>
   <logger message="TestBasicAuthOk"/>
</flow>
```

## HTTP Request, Response, and Error Response Body XML Example

Defining the body of an HTTP request, response, and error response is optional. When you do not
explicitly define the body element, the request or response returns the default payload.

The following example shows the XML configuration of an `http:request` operation that defines a
custom `body`, a key/value `query-parameter`, an X-Custom `header`, and a `uri-params` with the
`uriParamsMap` variable that populates the URI parameter `uriParam`:

```xml
<http:request path="/{uriParam}/test"  config-ref="reqConfig">
   <http:body>
       #['Custom body']
   </http:body>
   <http:headers>
       #[{'X-Custom' : 'custom'}]
   </http:headers>
   <http:uri-params>
       #[uriParamsMap]
   </http:uri-params>
   <http:query-params>
       #[{'key’' : 'value’'}]
   </http:query-params>
</http:request>
```

The following example shows the XML configuration of an `http:listener` source that lacks a defined
`body` element. The returned value is the default payload. The payload defines an `http:response` to
a successful execution that consists of a `200` `statusCode` and `Ok` as the `reasonPhrase`, with
`headers` `Name` as `content`, and `Something` as `someValue`:

```xml
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
   <http:response statusCode="200" reasonPhrase="Ok">
       <http:headers>
           #[{"Name" : "content", "Something" : someValue}]
       </http:headers>
   </http:response>
</http:listener>
```

The following example shows the XML configuration of an `http:listener` source that defines a
response to an execution failure that returns a `502` `statusCode` and `Failure` as the
`reasonPhrase`, with `headers` `Error` as `FIRE` and `body` as `Oops, something is wrong`:

```xml
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
   <http:error-response statusCode="502" reasonPhrase="Failure">
       <http:body>
           #[‘Oops, something is wrong’]
       </http:body>
       <http:headers>
           #[{"Error" : "FIRE"}]
       </http:headers>
   </http:error-response>
</http:listener>
```

## See Also

- [HTTP Connector Reference](https://docs.mulesoft.com/http-connector/latest/http-documentation)
