---
schema_version: "1"
id: e84f27e6d7bdd9c8986a9f5f396c7d5db6f77956fee4fda6bedefbf6f8e96db1
title: Consume a REST Service Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/http-connector/latest/http-consume-web-svc-task.md
canonical_url: https://docs.mulesoft.com/http-connector/latest/http-consume-web-svc-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 60993baaa54cba60335b4fd5b13a2595c0a4cd041333ef368d4a9f0b6870c9e2
description: MuleSoft Documentation Site
release: "1.12"
latest: true
---
---
product: HTTP Connector
version: 1.12
is-latest-version: true
---

# Consume a REST Service 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) to
consume a REST service by setting up the HTTP **Listener** source and the **Request** operation.

To accomplish this example, you must:

- Consume a REST API service using default HTTP configurations.

- Test the HTTP request.

- Edit the configuration to make secure HTTPS requests.

- Test the HTTPS request.

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

![Consume a REST API Service flow](/mulesoft/current/en-us/http-connector/latest/_images/http-consumerest-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.

2.  On the **Listener** configuration screen, optionally change the value of the **Display Name**
    field.

3.  Set **Path** to `/trigger`.

4.  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.

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

    - **Host**: `All Interfaces [0.0.0.0] (default)`

    - **Port**: `8081`

6.  Click **OK**.

    ![HTTP Listener global configuration](/mulesoft/current/en-us/http-connector/latest/_images/http-startapp-example-1.png)

    ![HTTP Listener configuration](/mulesoft/current/en-us/http-connector/latest/_images/http-startapp-example-2.png)

7.  Drag an HTTP **Request** operation to the right of HTTP **Listener**.

8.  Set **URL** to `http://jsonplaceholder.typicode.com/users`.

    ![HTTP Request configuration](/mulesoft/current/en-us/http-connector/latest/_images/http-consumerest-example-3.png)

9.  Save your Mule app.

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

11. Open a web browser, and go to `localhost:8081/trigger`.  
    The **Listener** hears the request on port `8081`, and starts the app. The list of users appears
    in the browser.

12. Return to the **Request** configuration screen and set the **URL** field to
    `https://jsonplaceholder.typicode.com/users` to use the HTTPS protocol.

13. 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 **Request** in the app.

14. Set **Port** to `443`.

15. Click **OK**.

    ![HTTP Request global configuration](/mulesoft/current/en-us/http-connector/latest/_images/http-consumerest-example-4.png)

16. Save and run your Mule app.

17. Open a web browser, and go to `localhost:8081/trigger`.  
    The **Listener** hears the request on port `8081`, and starts the app. The list of users appears
    in the browser.

## XML for Consuming a REST API Service

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

## See Also

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

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