Exposing an CSV Datasource

This example demonstrates how CSV data can be exposed as a data service.



Note that you can only read data from CSV files. The Micro Integrator does not support inserting, updating, or modifying data in a CSV file.

Download the Products.csv file.

This file contains data about products (cars/motorcycles) that are manufactured in an automobile company. The data table has the following columns: ID , Name , Classification , and Price.

Synapse configuration

Given below is the data service configuration you need to build. See the instructions on how to build and run this example.

Be sure to update the CSV datasource path.

<data name="CSV" transports="http https local">
   <config enableOData="false" id="CSV">
      <property name="csv_datasource">/path/to/csv/Products.csv</property>
      <property name="csv_columnseperator">,</property>
      <property name="csv_startingrow">2</property>
      <property name="csv_hasheader">true</property>
      <property name="csv_headerrow">1</property>
   <query id="Q1" useConfig="CSV">
      <result element="Products" rowName="Product">
         <element column="ID" name="ID" xsdType="string"/>
         <element column="Classification" name="Classification" xsdType="string"/>
         <element column="Price" name="Price" xsdType="string"/>
         <element column="Name" name="Name" xsdType="string"/>
   <operation name="GetProductsOp">
      <call-query href="Q1"/>
   <resource method="GET" path="Products">
      <call-query href="Q1"/>

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create a Data Service project.
  3. Create the data service with the configurations given above. Be sure to update the CSV datasource path.
  4. Deploy the artifacts in your Micro Integrator.

You can send an HTTP GET request to invoke the data service using cURL as shown below.

curl -X GET http://localhost:8290/services/CSV.HTTPEndpoint/Products

This will return the response in XML.


<?xml version="1.0" encoding="UTF-8"?>
<Products xmlns="http://ws.wso2.org/dataservice">
      <Name>1969 Harley Davidson
 Ultimate Chopper</Name>
      <Category>Classic Cars</Category>
      <Name>1952 Alpine Renault 1300</Name>
      <Name>1996 Moto Guzzi 1100i</Name>
      <Name>2003 Harley-Davidson Eagle Drag Bike</Name>
      <Category>Classic Cars</Category>
      <Name>1972 Alfa Romeo GTA</Name>
      <Category>Classic Cars</Category>
      <Name>1962 LanciaA Delta 16V</Name>
      <Category>Classic Cars</Category>
      <Name>1968 Ford Mustang</Name>
      <Category>Classic Cars</Category>
      <Name>2001 Ferrari Enzo</Name>