0

Spring Boot application hosting REST services at back-end and Angular at front-end. I am calling the REST from UI.

My Code

$http.get(urls.USER_SERVICE_API) .then( function (response) { console.log('Fetched successfully all users'); $localStorage.users = response.data; deferred.resolve(response); }, function (errResponse) { console.error('Error while loading users'); deferred.reject(errResponse); } ); app.constant('urls', { BASE: '<a class="vglnk" href="http://localhost:8081/SpringBootCRUDApp" rel="nofollow"><span>http</span><span>://</span><span>localhost</span><span>:</span><span>8081</span><span>/</span><span>SpringBootCRUDApp</span></a>', USER_SERVICE_API : '<a class="vglnk" href="http://localhost:8081/SpringBootCRUDApp/api/user/" rel="nofollow"><span>http</span><span>://</span><span>localhost</span><span>:</span><span>8081</span><span>/</span><span>SpringBootCRUDApp</span><span>/</span><span>api</span><span>/</span><span>user</span><span>/</span></a>' }); 

The error debug in Google chrome browser shows below :

angular.min.js:103 GET http://localhost:8081/SpringBootCRUDApp/%3Ca%20class=%22vglnk%22%20href=%22http://localhost:8080/SpringBootCRUDApp/api/user/%22%20rel=%22nofollow%22%3E%3Cspan%3Ehttp%3C/span%3E%3Cspan%3E://%3C/span%3E%3Cspan%3Elocalhost%3C/span%3E%3Cspan%3E:%3C/span%3E%3Cspan%3E8080%3C/span%3E%3Cspan%3E/%3C/span%3E%3Cspan%3ESpringBootCRUDApp%3C/span%3E%3Cspan%3E/%3C/span%3E%3Cspan%3Eapi%3C/span%3E%3Cspan%3E/%3C/span%3E%3Cspan%3Euser%3C/span%3E%3Cspan%3E/%3C/span%3E%3C/a%3E 404 

enter image description here

When calling the REST from POSTMAN, it is successful. Hence there is a problem while calling from the UI. Please help me to find out what I am doing wrong in the UI rest calling part.

Complete REST URL is :: http://localhost:8081/SpringBootCRUDApp/api/user/ 

Please help !

1
  • 1
    Dude... USER_SERVICE_API is '<a class="vglnk" href="http://localhost:8081/SpringBootCRUDApp/api/user/" rel="nofollow"><span>http</span><span>://</span><span>localhost</span><span>:</span><span>8081</span><span>/</span><span>SpringBootCRUDApp</span><span>/</span><span>api</span><span>/</span><span>user</span><span>/</span></a>, not http://localhost:8081/SpringBootCRUDApp/api/user/ as you expect.... Commented Jan 24, 2019 at 8:16

1 Answer 1

2

You have the wrong URL in your app.constants. Replacing that with the REST URL should give you the desired result.

USER_SERVICE_API: 'http://localhost:8081/SpringBootCRUDApp/api/user'

The URL currently specified by you has a lot of unknown tags in it.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. I have rectified the URL and removed all unnecessary tags . its working now. Thank You. app.constant('urls', { BASE: 'localhost:8081/SpringBootCRUDApp', USER_SERVICE_API : 'localhost:8081/SpringBootCRUDApp/api/user' });

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.