Skip to Content
Author's profile photo Former Member

OData model extension to consume plain REST services

Hello to all,

While searching arround for ways to consume a plain REST server with OpenUI5, I noticed there were only a few possibilities.

The JSON model was one of them.

But also the extension found here :

However, they did not fit my needs.

So, I decided to write my own. With some success.

My new try can be found on Github.

It includes an example to consume the Github REST api for its users and repos.

The result looks like this:


Main things to consider:

Normal REST does not prove metadata !!

Some of it is self-generated by this REST model.

Do do so, it needs info that is provided by setting a new parameter: the key.

(See source in Detail.controller.js)

  path : sRepoPath,
  sorter : {
   path : 'name',
   descending: false
  parameters :{

The new REST model self generates the metadata.

Many methods are are adopted to be able to create metadata.

RestModel.prototype._createmetakey = function(sPath, mParameters) {
var that = this;
if (!that.oMetadata.mEntityTypes[sPath]) {
that.oMetadata.mEntityTypes[sPath] = {};
var oEntityType = that.oMetadata.mEntityTypes[sPath];
if (!oEntityType["key"]) {
oEntityType["key"] = {};
var aKey = oEntityType["key"];
if (! {
if (mParameters && mParameters.key) {;
} else {
if (that.sKey) { = this.sKey;
} else { = "ID";
}, "Severe key error !!!");
// intercept creation of bindings to create metadata
RestModel.prototype.createBindingContext = function(sPath, oContext, mParameters, fnCallBack, bReload) {
// get key from params or settings
// mimics metadata info
this._createmetakey(sPath, mParameters);
return ODataModel.prototype.createBindingContext.apply(this, arguments);

Data retrieval is done by a normal ajax request.

This made it necessary to override some of the data retrieval methods.

Github uses different keys for different services.

users: login

repos: id.

To accomodate for this, keys are set in the main view and in the detail controller.

A main key can be set for the model as a whole.

var oModel = new"");

Please remember: this is work in progress. Readonly access for now.
Feedback is very welcome.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Fábio Luiz Esperati Pagoti
      Fábio Luiz Esperati Pagoti

      Don Alfredo,

      TBH I didn't get what are the limitations you are trying to avoid.

      Could you please explain that?

      Why can I use consume GitHub API using a simple JSONModel?


      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Sure you can consume REST (i.e. Github api) by using the JSON model !

      But there it stops.

      The OData model has the possibility of storing intermediate results of user edits, and advanced two way binding.

      And the use of some server side intelligence.

      And very automatic binding and efficient request for data.

      I expect the  OData model to gain many more usefull features in future.

      And with the model that I wrote, these features are also available for normal REST.


      It would have been MUCH MUCH better, if the OData model would have been an extension of an advanced REST model.

      I hope that one day, the people behind OpenUI5 will build an advanced REST model based on the current OData model, and with odata as an extension of this REST model.