Create a Data Service¶
Follow the instructions given below to create a new data service artifact.
Tip
You can also use a sample template to create your data service.
- Open the Explore Samples view of WSO2 Micro Integrator VS Code extension.
- 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.
Instructions¶
Create the data service artifact¶
Follow the steps given below to create the data service file:
-
Create a new integration project or select an existing one.
-
In the Micro Integrator: Project Explorer sidebar, hover over Data Services and click the + icon that appears to create a new data service.
This will open a form where you can configure the data service.
-
Enter a name for the data service and click Create.
A data service file (DBS file) will now be created in your data service project as shown below.
Add a datasource¶
You can configure the datasource connection details using this section.
-
Open the Service Designer page of the created data service and click on Edit to reopen the Data Service Form.
-
Click on the + Add Datasource to open the Create Datasource form.
-
Enter the datasource connection details.
-
Click Add to save the datasource configurations to the data service.
Advanced properties¶
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¶
Use this section to configure an REST resource to invoke the data service.
-
Select REST and click on + Resource to add a REST resource.
-
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.
-
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¶
Use this section to configure a SOAP operation for invoking the data service.
-
Select SOAP and click on + Operation to add a SOAP operation.
-
Give a name to the SOAP Operation, then click on Add.
-
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.
-
Click on Query to edit the query configuration.
-
Enter the following query details.
Parameter Description Query ID Provide a unique name to Identify the Query. Datasource All the datasources created for this data service are listed. Select the required datasource 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.
-
Click on the Input Mapping from the graphical view to edit the section.
-
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:
-
Click + Add Parameter.
-
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 -
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.
-
Click Output Mapping from the graphical view to edit the output mapping configurations.
-
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:
-
Click + Add Parameter.
-
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:
-
Examples¶
- Exposing an RDBMS Datasource
- Exposing Data in JSON Format
- Using an OData Service
- Using Nested Data Queries
- Batch Requesting
- Invoking Multiple Operations via Request Box
- Using Distributed Transactions in Data Services
- Validating Data Input