Skip to Content

OpenUI5 Mockserver configuration

Jul 21, 2017 at 05:35 AM


avatar image


Can anyone please explain how to config mock server in SAPUI5 and how to set rootUri.

What exactly rootUri pointing to?


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Hendrik Hilleckes Jul 21, 2017 at 06:02 AM

The rootUri is an artificial URI you can choose how you like. The important thing is that you point your oData model to that URI once the mockserver is running.

I always use the URI of the real service on the gateway. That way I can use the same model in my code.

Let me give you an example:

// assuming that your real service has the URI /sap/opu/odata/sap/my_service
// DO NOT forget the trailing slash!
sServiceUri = "/sap/opu/odata/sap/my_service/"

// in your component.js you have to detect that you are running local (or any other condition for starting the mockserver)
if(location.hostname === "localhost" || location.hostname === ""){

// in your mockserver.js you have to initialize the mockserver
this.oMockServer = new MockServer({
                rootUri: sServiceUri
   autoRespond: true,
   autoRespondAfter: 100
// get path to your metadata.xml and mockdata folder
var sPath ="");

this.oMockServer.simulate(sPath + "/metadata.xml", sPath + "/mockdata/");

// now you can create your model the same way you did it with a real service, e.g.
this._oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUri);
10 |10000 characters needed characters left characters exceeded