Receive HTTP Requests - Mule 4
Anypoint Connector for HTTP (HTTP Connector) has a Listener operation that receives requests over the HTTP or HTTPS protocol. Receiving a request and other incidents initiate a Mule event. The event passes the request body to the next element of the flow as the message payload. In addition to the payload, the Mule message includes attributes. You can refer to attributes, such as headers, query parameters, and so on using HttpRequestAttributes syntax.
When you configure an HTTP request, do not set the Content-Type header. The Mule runtime engine (Mule) automatically infers the header from the message payload. If you set the Content-Type header for payload formatted as
multipart/form-data, the HTTP request fails with a 400 error status.
The following diagram explains how to access information about the request.
You use DataWeave syntax to access this information.
The response to a request can include the following information:
You can configure a response for a successful or failed execution of the flow of the listener. By default, the former presents the payload as a body and yields a 200 status code. By default, the latter presents the error description as a body and yields a 500 status code.
The HTTP method most often configured for an HTTP or HTTPS Listener operation is GET. The HTTP Listener default allows all the HTTP Methods. Follow the best practice to limit the allowed HTTP methods to only the method or methods for your app.
Configure Allowed Methods in Advanced:
You can use Transport Layer Security (TLS) and configure HTTPS by providing a key store with your certificate. You can also enable 2-way authentication by providing a trust store. For details, see Configure TLS with Keystores and Truststores.