2

How to Protect my JSON Server Data in angularJS?

In the Controller I'm using the URL of the JSON Server Data, So, How Can I Protect it from the Client Side?

My JSON Server Data URL is http://www.w3schools.com/angular/customers.php

My Source Code is

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl"> 

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td><a href="" ng-click="SuperFunction('{{x.Name}}')">{{ x.Country }}</a></td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://www.w3schools.com/angular/customers.php")
    .then(function (response) { $scope.names = response.data.records; });
    $scope.SuperFunction = function (id) {
        alert(id);
    };
});
</script>

</body>
</html>
4
  • What do you mean to protect? Commented Dec 8, 2015 at 6:35
  • The Hacker Can easily access the JS file, from that he can easily get the JSON Data using the specified URL. How to Protect the Data from the Hacker? Commented Dec 8, 2015 at 6:41
  • 1
    You can't protect anything inside of client-side JavaScript, the best you can do is obfuscate. Commented Dec 8, 2015 at 6:53
  • "The Hacker"...in this case you mean user. That is the beauty of the web: view source. You can see and learn exactly what is happening in front of you. There are ways to obfuscate this data, but do so knowing that you are violating one of the tenets of the web. TBL created the web this way for all of us, not so you could profit of closed/siloed/proprietary nonsense.... ;) Commented Dec 8, 2015 at 7:06

1 Answer 1

3

You can't protect your Frontend code, it is visible to the user / hacker!

The best way of protecting information is a server side authentification (login)

But the api and the api calls (over dev tools) are always visible!

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.