I am attempting to retrieve data from a website using the HTTP GET method. This particular website requires basic authentication and the data is in JSON format. You can find the REST API website here: ()
// Insert your code here
angular.module('myapp', ['myapp.controller']);
angular.module('myapp.controller', ['myapp.service'])
.controller('testController', function($scope, testService) {
$scope.posts = {};
function GetAllPosts() {
var getPostsData = testService.getPosts();
getPostsData.then(function(post) {
$scope.posts = post.data;
}, function() {
alert('Error in getting post records');
});
}
GetAllPosts();
});
angular.module('myapp.service', [])
.service('testService', function($http) {
// Obtain all NewsLetter entries
this.getPosts = function() {
return $http.get('https://shoploapi.herokuapp.com/sellers');
};
});
angular.module('myApp', ['base64'])
.config(function($httpProvider, $base64) {
var auth = $base64.encode("bhupendra7:ice123age456");
$httpProvider.defaults.headers.common['Authorization'] = 'Basic ' + auth;
});
<!DOCTYPE html>
<html>
<head>
<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbbab5bcaeb7baa9befbfbfc6fef9ebbeb2bbf5fbefdab8e4fae3eeefe1bfd0d9dfdad99dd0da88eaedddeaedeee2bdcdcacccee8e3e9abb8e2ffec" href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e2ede4f6eff2c1bde9d0cafbd4decfd0afc4cea23418c4dc">[email protected]</a>" data-semver="1.5.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-base64/2.0.5/angular-base64.js"></script>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body ng-app="myapp">
<h1>Hello Plunker!</h1>
<div ng-controller="testController">
<div>
<ul>
<li ng-repeat="post in posts">
{{post.careof}} {{post.district}} {{post.gender}} {{post.name}}
</li>
</ul>
</div>
</div>
</body>
</html>
Check out my Plunker link for more details:
(https://plnkr.co/edit/7pqljm?p=preview)
Any assistance would be greatly appreciated.