cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting LocalHost API to UI5 application

Ajinkya_Jadhav
Participant
0 Kudos

Hi,

I have a python service running on my local host. I am able to get response through postman.

I want to call it in my UI5 application. When I try to directly use the URL "http://localhost:5000/upload4" it is giving CORS header error. When I created destination and then tried, it is giving 500 error now.

How can we do this?

Thank You.

Best Regards,

Ajinkya Jadhav

Accepted Solutions (0)

Answers (1)

Answers (1)

mariusobert
Developer Advocate
Developer Advocate

Hi,

CORS will prevent you from "accessing" web content from different sources. This includes other ports on localhost as well. You can work around this by setting an HTTP-header to allow it. But this problem might come back at you when you later want to deploy to production as the URL of the python app will be changed then.

You could use a local approuter to act as a reverse proxy on your local machine as well. This way, you won't have to adapt the app when deploying to production (as it will be independent of the URL). I've done the same thing in this sample app (with a Fiori Elements and a CAP app)

Ajinkya_Jadhav
Participant
0 Kudos

Didn't get completely:(

mariusobert
Developer Advocate
Developer Advocate
0 Kudos

I updated the phrasing of my answer.

If it's still unclear, please ask a followup question.

Ajinkya_Jadhav
Participant
0 Kudos

Hi Marius,

We have some issues to deploy our python API on cloud hence only for testing purpose i am running the code in my anaconda prompt and trying to access it with webide.

The code I am writing is as follows:

var settings = {
				"async": true,
				"crossDomain": true,
				"url": "http://localhost:5000/upload4", 
				"method": "POST",
				"headers": {
					"content-type": "application/json",
					"cache-control": "no-cache"
				},
				"processData": false,
				"data": "{\r\n\"Host\":\"10.100.222.533\",\r\n\"port\":111,\r\n\"Username\":\"abc\",\r\n\"Password\": \"xyz\"\r\n} "
			}


			$.ajax(settings).done(function (response) {
				console.log(response);
			});

I am able to get the response from postman hence no issues with the API. I need a temporary solution (as I am not going to deploy it to production) to access the API running on my localhost.

Hope the response makes question more clear to understand:)

Thank You.

Best Regards,

mariusobert
Developer Advocate
Developer Advocate
0 Kudos

OK, I'm afraid I don't know how this works exactly but you'll need to find a way to add a destination to the Web IDE Personal Edition.

In general, I recommend getting the API deployed to the cloud. I'm not sure if this temporary solution would actually save you time as it doesn't seem to be every easy.