Contact Us 1-800-596-4880

REST API Examples

These examples of consuming REST APIs show you how to perform typical tasks using Anypoint Studio or a standalone XML in Mule Runtime:

Overview of Consuming a REST API—​Studio

This example queries the Bacon Ipsum REST API at:

http://baconipsum.com/

This API generates lorem ipsum text. You don’t have to use HTTPS or set up an account. Initially, you add and configure an HTTP listener and an HTTP requester:

rest api examples ec226

At this point, you can call the API and receive bacon ipsum text in the browser. Next, you add a File component to the example to save the output of the request for lorem ipsum text to a file on your file system.

rest api examples 2d8e6

The first element, an HTTP listener, listens on localhost port 8081 (the default) for incoming GET requests. Calling the listener from a browser triggers the flow. Use the following syntax for requests:

http://localhost:8081?<query>

The <query> consists of the parameters accepted by the REST API. When the HTTP listener receives the HTTP request, the application records <query> as a set of inbound properties. The HTTP listener passes these properties to the next element in the flow, the HTTP request connector. This outbound connector is configured to query the remote REST API at http://baconipsum.com/api. The HTTP request connector uses MEL expressions to extract the query parameters from the properties in the message, and constructs the full URL for the remote API, including the query parameters.

For example, you enter this local browser request: http://localhost:8081?type=meat-and-filler.

The application issues this query: http://baconipsum.com/api/?type=meat-and-filler.

Follow the procedures in subsequent sections to create and run the example.

Configuring the HTTP Connectors

You need to specify how to call the API and what to return by configuring the HTTP Listener and HTTP requester.

HTTP Listener

  1. Select the HTTP listener component.

  2. In the properties editor, set the Path to /:

rest api examples bf47c

In Connector Configuration, click add, and set up the Host and Port:

rest api examples 876de
Parameter Value

Name

HTTP_Listener_Configuration

Host

localhost

Port

8081

HTTP Request Connector

  1. In Connector Configuration, click add, and set up the Host, Port, and Base Path:

    rest api examples fc78a
    Parameter Value

    Name

    HTTP_Request_Connector

    Host

    baconipsum.com

    Port

    80

    Base Path

    api

    This configuration sends requests to http://baconipsum.com/api.

  2. Click OK.

  3. In the properties editor, set up the path and method:

    Parameter Value

    Path

    /

    Method

    GET

    rest api examples e5e5f
  4. Add two parameters using Add Parameter. Accept the default type query-param for both. For the value field of each, write a mule expression that takes the specified value from the query parameters of the request that first reaches the HTTP Listener.

    The application transforms the parameters into inbound properties when they reach the HTTP request connector.

    rest api examples ba00e
    Parameter Value

    Type

    query-param

    Name

    type

    Value

    #[message.inboundProperties.'http.query.params'.type]

    Parameter Value

    Type

    query-param

    Name

    sentences

    Value

    #[message.inboundProperties.'http.query.params'.sentences]

The Bacon Ipsum API page contains a list of parameters you can use, but this application uses only type and sentences. An example of a valid value for type is meat-and-filler, as shown later. The optional sentences parameter determines the number of sentences to return in the JSON response.

File Outbound Endpoint

Set up the File connector properties to save the output of this application to a file.

  1. Drag a File connector onto the canvas.

  2. In the properties editor, set the directory and file name for storing the output: /tmp/output

    rest api examples 2d8e6
  3. In the properties editor, specify any actual path on your file system for Path.

    Mule runtime performs intermediate processes here, but does not write the output here.

  4. In File Name/Pattern, enter the name of an output file, for example output.

  5. In Connector Configuration, select File from the drop-down.

    rest api examples d0064
  6. In Connector Configuration, click add, and enter a path in Write to Directory. Enter /tmp for example.

    rest api examples 479e3

Running the Application to Consume a REST API

  1. Run the example as a Mule application.

  2. To trigger the flow in this application, use a Web browser to query the HTTP listener on localhost port 8081.

    rest api examples 4c1b4

    The console logs a message that the response was written to the file you specified:

    INFO 2016-05-22 17:40:56,406 [[myproject].HTTP_Listener_Configuration.worker.01] org.mule.transport.file.FileConnector: Writing file to: /private/tmp/output

Alternatively, you can use an HTTP client, such as the Curl command-line utility to trigger the flow.

curl 'http://localhost:8081?type=meat-and-filler'

The Bacon Ipsum API page contains a list of parameters you can use, but when configuring the HTTP request connector, you set up your connector to use only type and sentences. The first parameter=value pair must be preceded by the ? operator. To insert additional parameter=value pairs, use the & operator. Example queries you can send to the HTTP listener on localhost port 8081 are:

http://localhost:8081?type=meat-and-filler
http://localhost:8081?sentences=2
http://localhost:8081?type=all-meat&sentences=3

The type=meat-and-filler example returns the output shown below.

["Doner ullamco ea non, porchetta incididunt brisket ball tip in chuck ex bresaola beef tongue.  Et aute ham hock kielbasa chuck fatback short ribs.  Kevin in reprehenderit est esse, ham bacon ut ball tip.  Laborum ut nulla ex irure t-bone flank, biltong cupidatat venison proident aliquip pork belly ham hock.  In consequat proident, cillum labore pariatur nisi.  Reprehenderit boudin beef ribs, frankfurter cillum enim pork loin consectetur kielbasa laboris.  Hamburger prosciutto nisi, jerky biltong ex pork chop venison.","Fatback tongue anim, irure ut ut cupidatat occaecat eiusmod ham hock laborum commodo.  Anim pig shank kielbasa, drumstick corned beef esse nostrud ham salami id laborum ribeye aute.  Duis pancetta sunt magna occaecat dolor leberkas, short loin meatloaf flank enim pastrami.  Prosciutto proident landjaeger deserunt tenderloin short loin.  Adipisicing aute in bresaola meatball, ut frankfurter pastrami shoulder porchetta turducken strip steak doner.  In filet mignon bresaola, sed deserunt pariatur eu mollit commodo shankle laborum.  Andouille aliqua jowl pork chop jerky sed consequat turkey voluptate bacon pastrami.","Ground round elit boudin reprehenderit.  Brisket shankle esse, leberkas veniam andouille rump proident drumstick.  Consequat sausage do ut prosciutto nostrud andouille tongue ullamco bacon est exercitation.  Do fugiat biltong est tempor short ribs reprehenderit adipisicing shoulder.  Tail venison shank incididunt, hamburger adipisicing voluptate corned beef fugiat sirloin fatback in tri-tip nisi ut.  Tail non excepteur, fugiat veniam corned beef dolore ex pig pork belly sint mollit chuck pork.","Pig hamburger dolore proident brisket landjaeger in boudin kielbasa ut elit.  Velit incididunt boudin qui.  Fatback anim adipisicing, pig jowl voluptate sirloin drumstick chicken esse.  Strip steak consequat tenderloin pastrami, ullamco brisket hamburger bacon beef adipisicing.  Tri-tip ham hock eu non et, flank dolore kevin.  Et duis frankfurter, ut ullamco do non quis boudin andouille aliqua venison ham.  Ut aliqua shoulder, aliquip pariatur bacon spare ribs irure.","Aliqua jerky frankfurter, swine ham in ground round sed qui laborum cow.  Sint turducken shank ut ea id.  Kevin dolore pig excepteur, anim ut magna.  Enim consequat short ribs corned beef ham hock nostrud fugiat chuck.  Tail spare ribs dolore boudin, andouille incididunt laboris occaecat strip steak.  Cow frankfurter capicola, landjaeger cupidatat porchetta ad ground round voluptate."]

Consuming a REST API—​Standalone XML

Procedure

Configure the HTTP listener connector as follows:

<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>

You reference an abstract element called a Connector Configuration, which contains several of the high level necessary configuration properties. The config-ref attribute in the connector references this connector configuration element. You must now create an element outside the flow that matches the referenced name.

<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>

Configure the HTTP request connector as follows:

<http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP">
   <http:request-builder>
     <http:query-param paramName="type" value="#[message.inboundProperties.'http.query.params'.type]"/>
     <http:query-param paramName="sentences" value="#[message.inboundProperties.'http.query.params'.sentences]"/>
    </http:request-builder>
        </http:request>

A series of child elements of the connector define two query parameters that take their values from inbound properties of the message. Enclosing the two elements that define these query parameters is a request-builder element that is always necessary when adding parameters to a request. Configured in this way, the query params that reach the HTTP listener are forwarded unchanged to the baconipsum API.

You reference an abstract element called a Connector Configuration, which contains several of the high level necessary configuration properties. The config-ref attribute in the connector references this connector configuration element. You must now create an element outside the flow that matches the referenced name.

<http:request-config name="HTTP_Request_Configuration" host="baconipsum.com"  doc:name="HTTP Request Configuration" basePath="api"/>

Finally, add the file component.

<file:outbound-endpoint responseTimeout="10000" doc:name="File" connector-ref="File" outputPattern="output" path="/Users/max"/>

XML

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

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" 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:spring="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
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://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <http:request-config name="HTTP_Request_Configuration" host="baconipsum.com"  doc:name="HTTP Request Configuration" basePath="api" port="80"/>
    <file:connector name="File" writeToDirectory="/tmp" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
    <flow name="test2Flow1" >
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP" />
        <http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP">
          <http:request-builder>
                <http:query-param paramName="type" value="#[message.inboundProperties.'http.query.params'.type]"/>
                <http:query-param paramName="sentences" value="#[message.inboundProperties.'http.query.params'.sentences]"/>
            </http:request-builder>
        </http:request>
        <file:outbound-endpoint responseTimeout="10000" doc:name="File" connector-ref="File" outputPattern="output" path="/Users/max"/>
    </flow>
</mule>

Extracting and Storing XML Data from a REST API—​Studio

This example consumes XML data from an external REST API, extracts values from the XML, and inserts the values into a Postgres database. The application uses the Yahoo! REST API for financial services, which is free to use and does not require a user account. You call the API to retrieve financial quotes using the SQL-based Yahoo Query Language.

Overview of Extracting and Storing XML Data from a REST API

You specify the XML format when querying the Yahoo! REST API at http://query.yahooapis.com/v1/public/yql. The application receives the reply and extracts some values, such as stock name and price. Finally, the API inserts the values into a table in an external Postgres database.

The application contains one flow:

rest api examples 1cd70

The first element, an HTTP listener, listens on localhost port 8081 (the default) for incoming GET requests. Calling the listener triggers the flow. Requests to the HTTP listener must take the form:

http://localhost:8081?<query>

The <query> part of the request consists of the parameters accepted by the REST API. When the HTTP listener receives the HTTP request, the <query> part of the URL becomes a set of inbound properties. The HTTP listener passes the message to the next element in the flow, the HTTP request connector. The HTTP request connector uses a set of MEL expressions to extract the query parameters from the message and to construct the full URL for the remote API, including the query parameters.

The application queries the following URL:

http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ("BAC")%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=XML

This query retrieves information for ticker symbol BAC, Bank of America, in XML format:

View the XML returned by the REST API

<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2016-05-31T04:38:43Z" yahoo:lang="en-US">
  <results>
    <quote symbol="BAC">
        <Ask>14.87</Ask>
        <AverageDailyVolume>97748896</AverageDailyVolume>
        <Bid>14.86</Bid>
        <AskRealtime/>
        <BidRealtime/>
        <BookValue>23.12</BookValue>
        ...
        <PercentChange>+1.22%</PercentChange>
      </quote>
    </results>
</query>
<!--  total: 23  -->
<!--  main-6df7badb-1dfa-11e6-b981-e83935aedd3a  -->

The HTTP request connector passes the XML it receives from the API to a byte-array-to-string transformer, which converts the message payload to a string. Next, a splitter splits the message into parts. The splitter is configured to split the incoming message using the <quote> element in the XML as delimiter.

<results>
  <quote symbol="BAC">
...
  </quote>
</results>

The last component in the flow, a Database (JDBC) connector, receives each XML chunk corresponding to each queried symbol. The JDBC connector is configured to run the following SQL query:

INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');

Creating and Configuring the Flow

  1. Drag the following components and transformers to the canvas placing them left-to-right:

    • HTTP Listener

    • HTTP Requester

    • Byte Array to String

    • DOM to XML

    • Expression

    • Variable

    • Database

  2. Configure each component and transformer as described in the following sections.

HTTP Listener

  1. Select the HTTP Listener, and in the Properties editor of the HTTP listener connector, set the Path to /:

    rest api examples 2979f
  2. In Connector Configuration, click add, and set up the Host and Port:

    rest api examples c6d2d
    Parameter Value

    Name

    HTTP_Listener_Configuration

    Host

    localhost

    Port

    8081

HTTP Request Connector

  1. Select the HTTP Request Connector, and in the properties editor click add to create a new Connector Configuration Element.

  2. Set up the Host and Base Path:

    rest api examples 426f6
    Parameter Value

    Name

    HTTP_Request_Connector

    Host

    query.yahooapis.com

    Port

    80

    Base Path

    v1/public.yql

    This configuration sends requests to query.yahooapis.com/v1/public.yql

  3. Click OK.

  4. In the properties editor, set up the Path and Method:

    rest api examples 4ec20
    Parameter Value

    Display Name

    HTTP

    Path

    /

    Method

    GET

  5. Click Add Parameter three times to add the parameters shown in the following tables. Accept the default type query-param. For the value field of each, write a mule expression that takes the value of the query parameters of the request that first reaches the HTTP Listener, and transforms the values into inbound properties for delivery to the HTTP Request Connector.

    yahoo+http+w+params
    Parameter Value

    Type

    query-param

    Name

    q

    Value

    #[message.inboundProperties.'http.query.params'.q]

    Parameter Value

    Type

    query-param

    Name

    env

    Value

    #[message.inboundProperties.'http.query.params'.env]

    Parameter Value

    Type

    query-param

    Name

    format

    Value

    #[message.inboundProperties.'http.query.params'.format]

    Configured in this way, the API forwards the query params received by the HTTP listener to the Yahoo API.

  6. Select the Advanced tab on the left side panel of the connector, and check the Follow Redirects checkbox.

Byte Array to String Transformer

Set the MIME type to application/xml.

General Tab

Parameter Value

Display Name

Byte Array to String

Return Class

-

Ignore Bad Input

no

Encoding

-

MIME Type

application/xml

Splitter

The Splitter divides the incoming message into parts based on a user-defined XPATH expression. The expression conforms to the XPath syntax supported by MEL:

xpath3(xpath_expression, input_data, return_type)

where:

  • xpath_expression indicates the XML element, <quote> in this example, which returns the ticker symbol for a stock.

  • input_data is the payload received from the Byte Array to String.

  • return_type in this example is the NODESET type, which returns a DOM NodeList object.

    1. Select the Splitter in the flow.

    2. In the properties editor, configure the splitter as follows:

      General Tab

Parameter

Value

Display Name

Splitter

Enable Correlation

IF_NOT_SET (Default)

Message Info Mapping

-

Expression

#[xpath3('//quote', payload, 'NODESET')]

DOM to XML Transformer

The Dom To Xml transformer converts DOM objects to XML. No configuration is required.

Expression

The Expression component evaluates an expression.

  1. Select the Expression component.

  2. In the properties editor, create the following expressions for the name and book value of Bank of America stock:

    flowVars.dbName=xpath3('//Name');
    flowVars.dbBookValue=xpath3('//BookValue');
    rest api examples 3756b

    The expression extracts the values from the XML in preparation for storage in the database.

Variable

The Variable component creates a variable that represents the SQL INSERT statement.

  1. Select the Variable component.

  2. Configure the component as shown in the following screenshot and table:

    rest api examples 51c06

    General Tab

Parameter

Value

Display Name

Variable

Operation - Set Variable - Name

insertStatement

Value

INSERT INTO mystock(name,bookvalue) VALUES('[flowVars.dbName]','[flowVars.dbBookValue]');

Database Connector

In this procedure you set up and test a connection between the API and a Postgres database. First, ensure that you meet the prerequisites for working with the database.

Prerequisites

To successfully test the connection, you need to install and set up the database before configuring and testing the Database Connector.

  1. Install the correct database driver for your database in your Studio application.

  2. Add the Postgres driver to the build path.

  3. Start Postgres.

  4. Set up a database named stock with default user name postgres and password postgres.

  5. Connect to the stock database.

  6. Create a table named mystock. For example, on the psql command line enter the following query:

    CREATE TABLE mystock (id SERIAL PRIMARY KEY, name varchar, bookvalue money);

Configure the Database Connector

To configure the database connector in Studio:

  1. Click the Database Connector.

  2. In Connector Configuration, click add.

    The Choose Global Type dialog appears.

    rest api examples deccf
  3. Choose Generic Database Configuration, and click OK.

    The Generic Database Configuration dialog appears.

  4. In Database URL, enter the following URL, assuming you are using the default database password and user name for the stock database:

    jdbc:postgresql://localhost:5432/stock?password=postgres&user=postgres

  5. Enter the driver class name:

    org.postgresql.Driver

  6. Click Test Connection.

    rest api examples 82a84

    If the test fails, check that you meet the prerequisites.

  7. Click OK.

  8. In Operation, select Insert from the drop-down.

  9. In Query, select Dynamic from the Type drop-down.

  10. In the Dynamic query text box, enter the following query:

    INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');
    rest api examples 3678e

Running This Example

  1. Run the example as a Mule application.

  2. Call the HTTP listener with your query.

    Use a Web browser or an HTTP client, such as the Curl command-line utility, to call the HTTP listener on localhost port 8081. Remove any line breaks from the URL or curl command.

    http://localhost:8081?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20
    (%22BAC%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=XML
    curl 'http://localhost:8081?q=select%20*%20from%20yahoo.finance.quotes%20where
    %20symbol%20in%20(%22BAC%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2
    Falltables.env&format=XML'

    Calling the listener triggers the flow.

    PgAdmin III interface to Postgres shows the data inserted in the database row.

    rest api examples b8dd8

Consuming a REST API—​Standalone XML

Procedure

Configure the HTTP Listener connector as follows:

<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>`

You reference an abstract element called a Connector Configuration that contains several of the high level necessary configuration properties. The config-ref attribute in the connector references this connector configuration element. You must now create an element outside the flow that matches the referenced name.

<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>

Configure the HTTP Requester connector as follows:

<http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" followRedirects="true" doc:name="HTTP">
   <http:request-builder>
      <http:query-param paramName="q" value="#[message.inboundProperties.'http.query.params'.q]"/>
      <http:query-param paramName="env" value="#[message.inboundProperties.'http.query.params'.env]"/>
      <http:query-param paramName="format" value="#[message.inboundProperties.'http.query.params'.format]"/>
   </http:request-builder>
</http:request>

The series of child elements of the connector define three query parameters that take their values from inbound properties of the message. Enclosing the elements that define the query parameters is a request-builder element that is required for adding parameters to a request.

You now need to reference a Connector Configuration. The config-ref attribute in the connector references this connector configuration element. You must now create an element outside the flow that matches the referenced name.

<http:request-config name="HTTP_Request_Configuration" host="query.yahooapis.com" basePath="v1/public/yql" doc:name="HTTP Request Configuration"/>

Byte Array to String

<byte-array-to-string-transformer doc:name="Byte Array to String"/>

Splitter

<splitter expression="#[xpath3('//results')]" doc:name="Splitter"/>

Expression

<expression-component doc:name="Expression">
  <![CDATA[flowVars.dbName=xpath3('//Name');flowVars.dbBookValue=xpath3('//BookValue');]]>
</expression-component>

Variable

<set-variable variableName="insertStatement" value="INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');" doc:name="Variable"/>

Driver Configuration

<db:generic-config name="Generic_Database_Configuration" url="jdbc:postgresql://localhost:5432/stock?password=postgres&amp;user=postgres" driverClassName="org.postgresql.Driver" doc:name="Generic Database Configuration"/>

Database Configuration

<db:insert config-ref="Generic_Database_Configuration" doc:name="Database">
    <db:dynamic-query><![CDATA[INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');]]></db:dynamic-query>
</db:insert>

XML

<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:json="http://www.mulesoft.org/schema/mule/json"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
	xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:db="http://www.mulesoft.org/schema/mule/db"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
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://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">

	<http:listener-config name="HTTP_Listener_Configuration"
		host="localhost" port="8081" doc:name="HTTP Listener Configuration" />
	<http:request-config name="HTTP_Request_Configuration"
		host="query.yahooapis.com" basePath="v1/public/yql" doc:name="HTTP Request Configuration" />
	<context:property-placeholder location="common.properties" />
    <db:generic-config name="Generic_Database_Configuration" url="jdbc:postgresql://localhost:5432/stock?password=postgres&amp;user=postgres" driverClassName="org.postgresql.Driver" doc:name="Generic Database Configuration"/>

	<flow name="financeapiFlow1">
		<http:listener config-ref="HTTP_Listener_Configuration"
			path="/" doc:name="HTTP" />
		<http:request config-ref="HTTP_Request_Configuration"
			port="80" path="/" method="GET" doc:name="HTTP">
			<http:request-builder>
                <http:query-param paramName="q" value="#[message.inboundProperties.'http.query.params'.q]"/>
                <http:query-param paramName="env" value="#[message.inboundProperties.'http.query.params'.env]"/>
                <http:query-param paramName="format" value="#[message.inboundProperties.'http.query.params'.format]"/>
			</http:request-builder>
		</http:request>
        <byte-array-to-string-transformer mimeType="application/xml" doc:name="Byte Array to String"/>
	<!-- 	<splitter expression="#[flowVars.results]" doc:name="Splitter" />
	-->

		<splitter expression="#[xpath3('//quote', payload, 'NODESET')]"
            doc:name="Splitter" />
        <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
        <expression-component doc:name="Expression"><![CDATA[flowVars.dbName=xpath3('//Name');
flowVars.dbBookValue=xpath3('//BookValue');
]]></expression-component>
        <set-variable variableName="insertStatement" value="INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');" doc:name="Variable"/>
        <db:insert config-ref="Generic_Database_Configuration" doc:name="Database">
            <db:dynamic-query><![CDATA[INSERT INTO mystock(name,bookvalue) VALUES('#[flowVars.dbName]','#[flowVars.dbBookValue]');]]></db:dynamic-query>
        </db:insert>
	</flow>
</mule>

If you use the API to query several stock symbols at once, the splitter splits the incoming XML into chunks corresponding to each queried symbol, then feeds each chunk to the next message processor.