Back To Blogs
Paul Dale 3rd May 2018

A guide to OData (Exposing and Consuming an OData Feed using Mendix)

First of all, what is OData? Well, the official OData website says it best:

“OData (Open Data Protocol) is an ISO/IEC approved, OASIS standard that defines a set of best practices for building and consuming RESTful APIs. “

What’s it used for? OData is perfect for retrieving data from multiple data sources quickly and easily. It is very common in Business Intelligence (BI) tools, most popular BI tools allow you to connect to a OData feed directly and with ease, examples include:

  • Microsoft Power BI
  • Tableau
  • SAP Data Services

Even Excel provides an easy way to connect to an OData feed which we will look in to later, for now let’s get started on creating an OData source using Mendix.

Start by creating a new app in the Mendix Modeler. Conveniently Mendix provide starter apps which are perfect for this, so I’m going to use the asset manager starter, however there is nothing stopping you from following this tutorial using your own already built app(s).

Start by right clicking MyFirstModule and adding a new folder called OData Services. Your project explorer should look like this:

Right click the new folder and select ‘Add  Published Services  Published OData Service’. Give the service a name -I named mine ‘Assets’- and click okay on the configuration window that appears afterwards (we shall configure that later). Now open the domain model.

Next open the data model for your app. It’s here where we can choose what data you want to expose as an OData feed; right click the assets entity and select ‘Expose as OData resource’ then select our published OData service that we created earlier

You should now be able to name the exposed entity and select which attributes you want to expose by clicking the ‘Select’ button, I named mine ‘GetAssets’

Now you can simply check or uncheck the attributes you want to expose via the OData feed as well as change the name that is exposed. When you’re done click ‘OK’ and ‘OK’ on the previous window, you should now have this window:

We can at this point test our OData feed, but before that let’s take a look at the settings tab:

We can specify a namespace for the service and also see where our Service feed is located, as well as the metadata file that Mendix generates. Lastly, there is the security options where you can select an already created role and lock down the feed to a particular user or group of users, this is incredibly important in production systems and must be configured before going live.

Now let’s test our newly created OData feed! Click the ‘OK’ button and deploy your app locally. Wait for Mendix to finish processing then navigate to the URL specified in the settings of the published OData feed. If all is well you should get an XML document that lists all the resources you created (I only have one: ‘GetAssets’) if you type that after the last forward slash in the URL bar you should get an XML document with all the data. The URL should look something like this if you have followed the tutorial:

http://localhost:8080/odata/Assets/GetAssets

If you have data in XML form, then congratulations! You have successfully created an OData service using Mendix. If you get an error, then go back and re follow the steps to try and find the problem.

Using Excel to Consume the Feed
The XML document is great, but it’s not particularly easy to read. We can use Excel to quickly consume the service and display the data in a much more appealing format. Start by opening a new blank Excel document then selecting the Data tab on the ribbon, from there select ‘Get Data’  ‘From Other Source’  ‘From OData Feed’

Enter the URL to our GetAssets OData feed and click OK:

You should get a preview of the returned data and an option to edit but for simplicity’s sake just click ‘Load’. Excel should now load the entire data set and present the information to you:

Any number fields will appear as scientific notation by default, but the column can easily be reformatted to numbers. The data can be filtered down and queried using URL parameters, Mendix has very good documentation on doing this:

This is a very basic example of exposing and consuming an OData feed, but it does show how quickly they can be set up particularly if using a low code platform like Mendix or K2. Combining this with the wide support for OData from reporting tools, rich reporting on systems can be achieved very quickly and easily meaning less time and money is spent on development of these features.

References

http://www.odata.org/
https://docs.mendix.com/refguide/odata-query-options

Related Blogs


Why every manufacturer should be looking at low-code to enable transformation

The need for digitalisation has never been so apparent. The manufacturing industry is no exception to this and has seen much disruption in recent years, from supply chain issues as a result of the global pandemic to dealing with shifting buyer preferences and increased product complexity.

Find Out More

A deep dive into the low-code phenomenon

Low-code development has been gaining prominence amidst emerging technological solutions. The digital transformation era we live in today is a time of rapid technological advances and within this Digital Age, businesses are constantly grappling with digital disruptions and an increasing demand for software applications.

Find Out More

Leveraging machine learning capabilities in application development

In recent years, the digital sector has been transformed by artificial intelligence (AI). With tools such as ChatGPT and DALL-E, public access to AI resources is at an all-time high.

Find Out More

Why low-code IS a matter for the board

Before I speak to customers about their technology requirements, my first question is: “What are you trying to achieve as a company?” A quick look at their annual report and the evidence is clear to see – since corporate strategic objectives are set by the board and published to the markets. Almost without exception, these objectives will be aligned to growing revenue and reducing cost.

Find Out More

Low-code journey of a graduate developer

Fundamentally, what I enjoy is the process of developing software and the satisfaction of delivering high-quality products. When I was considering how this may map out my future career path, I knew that I wanted to work with technologies that would enable me to solve business problems, but also realised that I didn’t want to follow the traditional coding development route.

Find Out More
Drag