---
schema_version: "1"
id: 7baf919480ee67cc9af14b03deec795055fd36d2ad689de3d27771967c7bba4c
title: HTTP メソッドに基づく要求の転送の例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/http-connector/1.8/http-route-methods-based-task.md
canonical_url: https://docs.mulesoft.com/jp/http-connector/1.8/http-route-methods-based-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ee77f9d5afca9e39cc8eaa231a391dcdd45804b08fcc7719aefc542bbf620405
description: MuleSoft Documentation Site
release: "1.8"
latest: false
---
# HTTP メソッドに基づく要求の転送の例

次の例は、HTTP メソッドに基づいて要求を転送するように HTTP 用 Anypoint Connector (HTTP Connector) の ​**Listener**​ 操作を設定する方法を示しています。この例を実行するには、Mule アプリケーションを作成し、HTTP グローバル要素を設定し、アプリケーションを実行し、curl コマンドでアプリケーションをテストする必要があります。

次のスクリーンショットは、この例の Anypoint Studio アプリケーションフローを示しています。

![HTTP メソッドに基づく要求の転送のフロー](/mulesoft/current/ja-jp/http-connector/1.8/_images/http-routemethod-flow.png)

## [](#mule-アプリケーションの作成)Mule アプリケーションの作成

Mule フローを作成する手順は、次のとおりです。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、\[HTTP\] の ​**\[Listener\]**​ ソースを選択してキャンバスにドラッグします。  
    このソースは受信 HTTP メッセージ属性をリスンすることでフローを開始します。
2. Web ブラウザーからアプリケーションを開始するように ​**\[Path (パス)\]**​ 項目を ​`requests`​ に設定します。
3. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内の HTTP の ​**Listener**​ のすべてのインスタンスで使用できるグローバル要素を設定します。
4. **\[General (一般)\]**​ タブで、次の項目を設定します。
    
    - **Host (ホスト)**​: `localhost`
    - **Port (ポート)**​: `8081`
    - **Base Path (ベースパス)**​: `mypath`
5. **\[OK\]**​ をクリックします。
6. **\[Logger\]**​ コンポーネントを \[HTTP\] の ​**\[Listener\]**​ ソースの右にドラッグします。
7. **\[Message (メッセージ)\]**​ 項目を ​`flow 1`​ に設定します。
8. \[HTTP\] の別の ​**\[Listener\]**​ ソースを最初のフローの下にドラッグして、2 番目のフローを作成します。
9. **\[Connector Configuration (コネクタ設定)\]**​ 項目を、最初の ​**Listener**​ 用に作成したグローバル要素である ​`HTTP_Listener_Config`​ に設定します。
10. **\[Path (パス)\]**​ 項目を ​`requests`​ に設定します。
11. コネクタ設定画面で、​**\[Advanced (詳細)\]**​ タブを選択し、​**\[Allowed Methods (許可されるメソッド)\]**​ 項目を ​`POST`​ に設定します。
12. 別の ​**\[Logger\]**​ コンポーネントを \[HTTP\] の ​**\[Listener\]**​ ソースの右にドラッグします。
13. **\[Message (メッセージ)\]**​ 項目を ​`flow 2`​ に設定します。
14. Mule アプリケーションを保存します。
15. **Package Explorer**​ でプロジェクト名をクリックし、​**\[Run (実行)\]**​ > ​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
16. ブラウザー拡張機能で、HTTP ​`GET`​ および ​`POST`​ 要求を ​`http://localhost:8081/mypath/requests`​ に送信します。
    
    `GET`​ 要求応答は ​`flow 1`​ です。​`POST`​ 要求応答は ​`flow 2`​ です。
17. `DELETE`​ 要求を送信します。
    
    `DELETE`​ は許可されないメソッドであるため、​`405 Method Not Allowed`​ メッセージが返されます。

## [](#http-メソッドに基づいて要求を転送するための-xml)HTTP メソッドに基づいて要求を転送するための XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

```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>
```

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)