Angularjs + PHP: How should data be consumed?

Asked

Viewed 538 times

3

Starting some readings on the Angularjs for a possible future project, it came to my mind some doubts regarding the client/server integration and the consumption of the data provided by the server.

How should this be done? Through REST, or there is another way?

  • 2

    I also have this question. I do not know how to develop with angular, but I develop with back end and I need to know something about the angular to integrate with the back end.

1 answer

4


How should this be done? Through REST, or there is another way?

You need to have an API (in most cases it is used REST but I’ve seen with SOAP) that will be consumed in your application Angular. Who will make the connection to database, business rule and the like will be the API, the application Angular will only worry about sending requests to the API.

Basically you will develop, maintain and publish the backend separate from your frontend.

About the development and consumption of REST Apis

Angular itself provides resources for consuming REST services, such as the service $http and the ngResource and there are some frameworks PHP that can help you developer your REST API as the Laravel and the Slim Framework.


One simple example of what it’s like to consume a REST API using $http

function HelloWorld($scope, $http) {
    $http.get('http://restservice.com:1233/HelloWorld').
        success(function(data) {
            $scope.hello = data;
       });
}
  • I read about Slim, currently using Cakephp. So REST is the best option to work with Angularjs?

  • Well, there comes a little opinion and my opinion is that yes, REST is the best option to work with Angular.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.