Skip to content

Create a Data Service

Create the data service artifact

Follow the instructions given below to create a new data service artifact in the WSO2 Integrator: MI for Visual Studio Code extension (MI for VS Code).

  1. Launch Visual Studio Code with the WSO2 Integrator: MI for VS Code extension (MI for VS Code) installed.

    Info

    Follow the Install WSO2 Integrator: MI for VS Code documentation for a complete installation guide.

  2. Create an integration project.

  3. To add a new data service artifact, navigate to WSO2 Integrator: MI Project Explorer.

  4. Click on the + icon to open the Add Artifact pane.

    add artifact

  5. Click + View More under Create an Integration.

  6. Click Data Service under Other Artifacts to open the Data Service Form where you can configure the data service.

  7. Enter a name for the data service.

  8. Specify other required properties.

Add a data source

You can configure the data source connection details in this step.

  1. Go to the Service Designer of the created data service and click on Edit to reopen the Data Service Form.

  2. Click on the + Add Datasource to open the Create Datasource form.

  3. Enter the data source connection details.

  4. Click Add to save the data source configurations to the data service.

  5. Click Advanced Configurations to expand the section and add the required configurations.

The data service should now have the query element added.

Add a resource

In this step, you can configure a REST resource to invoke the data service.

  1. Select REST and click on + Resource to add a REST resource.

  2. Give the following details to create the REST resource.

    Parameter Description
    Resource Path Give the HTTP REST resource path you need to expose.
    Resource Method Select the REST API method from the drop-down list.

    Click Add to add the resource to the data service.

  3. Go to the Service Designer view and click on the added resource to open the graphical view.

    The graphical view will appear as shown below. You can use it to configure the main query details.

Add a SOAP operation

In this step you can configure a SOAP operation for invoking the data service.

  1. Select SOAP and click on + Operation to add a SOAP operation.

  2. Give a name to the SOAP Operation, then click on Add.

  3. Click on the added operation to open the graphical view.

    The graphical view will appear as shown below. You can use it to configure the main query details.

Create queries for REST resources and SOAP operations

You can configure the main query details for both SOAP operations and REST resources using their respective graphical views.

  1. Click on Query to edit the query configuration.

  2. Enter the following query details.

    Parameter Description
    Query ID Provide a unique name to Identify the Query.
    Datasource All the data sources created for this data service are listed. Select the required data source from the list.
    Query / Expression You can enter the SQL query in this text box.

    Provide the required parameter values in the Advanced Properties section.

Input mapping

You can configure input parameters for the query using this section.

  1. Click on the Input Mapping from the graphical view to edit the section.

  2. There are two ways to create the mapping:

    • You can use the default configurations to automatically generate the input mappings from the SQL query.
    • If you want to add a new input mapping:

      1. Click + Add Parameter.

      2. Enter the following input mapping details:

        Parameter Description
        Mapping Name Enter a name for the mapping.
        Query Parameter Enter the query parameter.
        Parameter Type The parameter type
        SQL Type The SQL type

      3. Save the input mapping. You can add multiple input mappings as required.

    Shown below is an example query with input mapping:

Result (output mappings)

You can configure output result parameters for the query using this section.

  1. Click Output Mapping from the graphical view to edit the output mapping configurations.

  2. There are two ways to create the output mapping:

    • You can use the default configurations to automatically generate the output mappings from the SQL query.
    • Alternatively, you can manually add the mappings:

      1. Click + Add Parameter.

      2. Enter the following output element details.

        Property Value
        Datasource Type column
        Output Field Name EmployeeNumber
        Datasource Column Name EmployeeNumber
        Schema Type String

      Follow the same steps to create the remaining output elements.

      Shown below is an example query with output mappings:

Tutorials

Follow our tutorial on data services:

Examples

Follow our examples on data services:

Samples

You can use a sample template to create your data service.

  1. Go to Explore Samples in MI for VS Code.
  2. In the Samples tab, go to the REST Data Service and click on Download. This will download the project to your chosen directory and open it in a new VS Code window.

For more information