Skip to Content
0

SAPUI5 external api fetch problem

Nov 02, 2017 at 11:33 AM

78

avatar image
Former Member

Dear experts,

I have created a simple application using SAP Web IDE FullStack.

In the onInit function of my controller, I am trying to access an external endpoint. My destination is the following:

My neo-app.json looks like this:

{
  "welcomeFile": "/webapp/index.html",
  "routes": [
    {
      "path": "/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources"
      },
      "description": "SAPUI5 Test Resources"
    }, {
		"path": "/joke",
		"target": {
			"type": "destination",
			"name": "joke",
			"entryPath": "/"
		},
		"description": ""
	}
  ],
  "sendWelcomeFileRedirect": true
}

controller.js onInit function:

var jokesModel = new JSONModel();

fetch("/joke/jokes/random/15").then(function(data){
     return data.json();
}).then(function(data){
     jokesModel.setData(data.value);
}).catch(function(err){
	MessageToast.show("Something went wrong... " + err);
});

Placing a debugger in the first resolved method shows that my response data is completely wrong:

HTTP 503 - Service Unavailable.

However, if I provide a hard coded URL to the fetch function the GET request will be successful, and then I am able to parse the body and store it without any problem.

Unfortunately I have no idea what causes this error, so any help is appreciated.

dest-scp.jpg (47.9 kB)
fetch-succ.jpg (56.1 kB)
debug-fetch.jpg (92.2 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Arjun Biswas Nov 03, 2017 at 04:10 AM
0

Have you tried configuring the destinations in your neo-app.json file.

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

In the routes array of my neo-app.json there is an object. Is there anything else I should do here?

{
		"path": "/joke",
		"target": {
			"type": "destination",
			"name": "joke",
			"entryPath": "/"
		},
		"description": ""
	}
0

Basically you are not able to read the data only. I think the problem is there with your destinations and configuring them. Could you check them again and try. Check if the destination is connecting or not.

0