---
schema_version: "1"
id: 1374a31f909ea5360190e413015dd432f9c772f0e57c7ed53e0c64988d8b6586
title: Route Requests Based on an HTTP Method Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/http-connector/1.10/http-route-methods-based-task.md
canonical_url: https://docs.mulesoft.com/http-connector/1.10/http-route-methods-based-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4ed98b31b6fdc5d01a5424579d135bc6780b527ccc3a1d9da3ac4850aa1236a3
description: MuleSoft Documentation Site
release: "1.10"
latest: false
---
---
product: HTTP Connector
version: 1.10
---

# Route Requests Based on an HTTP Method Example

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

The following example illustrates how to configure Anypoint Connector for HTTP (HTTP Connector)
**Listener** operation to route requests based on an HTTP method. To accomplish this example, you
must create the Mule app, configure an HTTP global element, run, and test the app with curl
commands.

The following screenshot shows the Anypoint Studio app flow for this example:

![Route Requests Based on an HTTP Method flow](/mulesoft/current/en-us/http-connector/1.10/_images/http-routemethod-flow.png)

## Create the Mule Application

To create the Mule flow:

1.  In the **Mule Palette** view, select the HTTP **Listener** source and drag it on to the
    canvas.  
    The source initiates the flow by listening for incoming HTTP message attributes.

2.  Set the **Path** field to `requests` to start the app from the web browser.

3.  Click the plus sign (**+**) next to the **Connector configuration** field to configure a global
    element that can be used by all instances of the HTTP **Listener** in the app.

4.  On the **General** tab, configure the following fields:

    - **Host**: `localhost`

    - **Port**: `8081`

    - **Base path**: `mypath`

5.  Click **OK**.

6.  Drag a **Logger** component to the right of the HTTP **Listener** source.

7.  Set the **Message** field to `flow 1`.

8.  Create a second flow by dragging another HTTP **Listener** source below the first flow.

9.  Set the **Connector Configuration** field to `HTTP_Listener_Config`, the global element you
    created for the first **Listener**.

10. Set the **Path** field to `requests`.

11. In the connector configuration screen, select the **Advanced** tab, and set the **Allowed
    methods** field to `POST`.

12. Drag another **Logger** component to the right of the HTTP **Listener** source.

13. Set the **Message** field to `flow 2`.

14. Save your Mule app.

15. Click the project name in **Package Explorer** and then click **Run** > **Run As** > **Mule
    Application**.

16. In your browser extension send an HTTP `GET` and `POST` requests to
    `http://localhost:8081/mypath/requests`.

    The `GET` request response is `flow 1`. The `POST` request response is `flow 2`.

17. Send a `DELETE` request.

    The `405 Method Not Allowed` message is returned because `DELETE` is not an allowed method.

## XML for Routing Requests Based on an HTTP Method

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	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:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config"  basePath="mypath" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<flow name="Flow1" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="requests"/>
		<logger level="INFO" doc:name="Logger" message="flow 1"/>
	</flow>
	<flow name="Flow2" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="requests" allowedMethods="POST"/>
		<logger level="INFO" doc:name="Logger" message="Flow 2"/>
	</flow>
</mule>
```

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
