cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to Connect Northwind Odata Service through UI5!

0 Kudos
775

Hi,

I am trying to consume an Odata Service through JS code only (No Cloud Connector)

Controller:

var url = "https://services.odata.org/V2/Northwind/Northwind.svc/";

var oModel = new sap.ui.model.odata.v2.ODataModel({ serviceUrl: url});

oModel.read("Categories",
{ 
method: "GET",

success:
function (data) {
// read data Success },

error:
function () {}
});

I am getting CORS Error as attached in image

Accepted Solutions (0)

Answers (1)

Answers (1)

geert-janklaps
Active Contributor

Hi,

You can't use a direct url to another domain in your frontend applications. You'll have to use a proxy for that purpose.

In SAP Cloud Platform you can easily do that by creating a destination and use the destination in your SAPUI5 app.

Creating a destination for the Northwind service is described here:

https://developers.sap.com/tutorials/hcp-create-destination.html

Best regards,

Geert-Jan Klaps

0 Kudos

So how can we consume Non Odata Rest API?

0 Kudos

I understand It will work perfectly with SAP Destinations GUI.

What i am trying to achieve here is to access an Odata Service directly through Code, since it is an API and it should be consumed anywhere by any language and I am trying to consume in Javascript.

geert-janklaps
Active Contributor

Hi,

This limitation you're running into is actually a security mechanism of web browsers. Some more information about those can be found here:

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
https://en.wikipedia.org/wiki/Same-origin_policy

You can't integrate an API call to another domain directly in a frontend application, you'll have to put at least a proxy script which runs within the same domain in between. This can be done using e.g. NodeJS, PHP, ... (or if it's runing in SAP Cloud Platform, by configuring a destination).

Best regards,

Geert-Jan Klaps