WSO2 Data services: Automatic CRUD services

We had already done a post about how to do REST data services with WSO2, here. Today we will see the OData services. Or what is the same, the automatic generation of REST data services. OData refers to Open Data Protocol, an OASIS standard. This standard defines the good practices to build and consume a RESTful API. It is something quite simple to do but I think it is a feature of WSO2 that not many people know.

To be able to automatically generate these web services, we must follow the next steps from the administration console:
- Create a new data service
- Associate a data source, with the difference that we must mark the option to enable OData.
- Save the data source and finish editing the data service.
If we see the code we can verify that it is a very simple data service:

Only with this WSO2, will generate a CRUD service for each table of the data source that we have indicated. This is an important point because if the data source contains system tables, the data service generation will fail. And if you want to create a CRUD for database views is only possible if we apply a WUM on the Enterprise Integrator.

Once generated, let’s see how we can get all the data from the BOOK table

If we see the previous call we must be aware of some details:

  • The port for HTTP call is still 8280 and 8243 for HTTPS.
  • The context for invoking these services is odata and not services.
  • We still need to put the name of our data service. In this case, it is ODataSample.
  • After the name of the data service we must indicate the name of the data source we have configured. In this case ODataDS.
  • Finally we must indicate the name of the table. In our example, BOOK.

Also associated to GET method we can do the following operations:

  • If we do not indicate any table. The call will show us the information of the different existing tables.
  • If we do not indicate any table, add to the path /$metadata and we invoke it as application/xml, it will return the format information of all the tables of the data source.
  • If we want to obtain only certain fields from a table we must add ?$select=fieldName, with the name of the fields to obtain separated by commas.


  • If we want to filter the table data we will add to the path ?$filter=fieldName eq ‘fieldValue’.


If we want to delete a record we will make the following call:

To create a record we must use the POST method as usual and indicate in the body of the call the fields to be entered.

And finally, to make an update, we will use the PUT method.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store