---
schema_version: "1"
id: 958c43ae640a24e55050797bd89df900e70d3bda0a419b937c18bc1d17988312
title: REST サービスのコンシュームの例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/http-connector/1.9/http-consume-web-svc-task.md
canonical_url: https://docs.mulesoft.com/jp/http-connector/1.9/http-consume-web-svc-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e6d679574ef5a21393bf6e31c9c674aa1fbab2c3a506da0172a036ecac59728b
description: MuleSoft Documentation Site
release: "1.9"
latest: false
---
# REST サービスのコンシュームの例

次の例は、HTTP の ​**Listener**​ ソースと ​**Request**​ 操作をセットアップして、REST サービスをコンシュームするように HTTP 用 Anypoint Connector (HTTP Connector) を設定する方法を示しています。

この例を実行するには、次の操作が必要です。  

- デフォルトの HTTP 設定を使用して REST API サービスをコンシュームします。
- HTTP 要求をテストします。
- セキュアな HTTPS 要求を実行するように、設定を編集します。
- HTTPS 要求をテストします。

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

![REST API サービスのコンシュームのフロー](/mulesoft/current/ja-jp/http-connector/1.9/_images/http-consumerest-flow.png)

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

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

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、\[HTTP\] の ​**\[Listener\]**​ ソースを選択してキャンバスにドラッグします。  
    このソースは受信 HTTP メッセージをリスンすることでフローを開始します。
2. **\[Listener (リスナー)\]**​ 設定画面で、必要に応じて ​**\[Display Name (表示名)\]**​ 項目の値を変更します。
3. **\[Path (パス)\]**​ を ​`/trigger`​ に設定します。
4. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内の HTTP ​**Listener**​ のすべてのインスタンスで使用できるグローバル要素を設定します。
5. **\[General (一般)\]**​ タブで、次の項目を設定します。
    
    - **Host (ホスト)**​: `All Interfaces [0.0.0.0] (default)`
    - **Port (ポート)**​: `8081`
6. **\[OK\]**​ をクリックします。
    
    ![HTTP リスナーのグローバル設定](/mulesoft/current/ja-jp/http-connector/1.9/_images/http-startapp-example-1.png)
    
    ![HTTP リスナーの設定](/mulesoft/current/ja-jp/http-connector/1.9/_images/http-startapp-example-2.png)
7. \[HTTP\] の ​**\[Request\]**​ 操作を \[HTTP\] の ​**\[Listener\]**​ の右にドラッグします。
8. **\[URL\]**​ を ​`https://jsonplaceholder.typicode.com/users`​ に設定します。
    
    ![HTTP 要求の設定](/mulesoft/current/ja-jp/http-connector/1.9/_images/http-consumerest-example-3.png)
9. Mule アプリケーションを保存します。
10. **Package Explorer**​ でプロジェクト名をクリックし、​**\[Run (実行)\]**​ > ​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
11. Web ブラウザーを開き、​`localhost:8081/trigger`​ に移動します。  
    **Listener**​ がポート ​`8081`​ で要求を検出し、アプリケーションを開始します。ユーザーのリストがブラウザーに表示されます。
12. **\[Request\]**​ 設定画面に戻り、HTTPS プロトコルを使用するように ​**\[URL\]**​ 項目を ​`https://jsonplaceholder.typicode.com/users`​ に設定します。
13. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内の HTTP ​**要求**​のすべてのインスタンスで使用できるグローバル要素を設定します。
14. **\[Port (ポート)\]**​ を ​`443`​ に設定します。
15. **\[OK\]**​ をクリックします。
    
    ![HTTP 要求のグローバル設定](/mulesoft/current/ja-jp/http-connector/1.9/_images/http-consumerest-example-4.png)
16. Mule アプリケーションを保存して実行します。
17. Web ブラウザーを開き、​`localhost:8081/trigger`​ に移動します。  
    **Listener**​ がポート ​`8081`​ で要求を検出し、アプリケーションを開始します。ユーザーのリストがブラウザーに表示されます。

## [](#rest-api-サービスをコンシュームするための-xml)REST API サービスをコンシュームするための 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" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" >
		<http:request-connection port="443" />
	</http:request-config>
	<flow name="Flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/trigger"/>
		<http:request method="GET" doc:name="Request"  config-ref="HTTP_Request_configuration" url="https://jsonplaceholder.typicode.com/users"/>
	</flow>
</mule>
```

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

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