AngularJS + PHP: How should the data be consumed?

3

Beginning some readings on the AngularJS for a possible future project, I came to mind some doubts about client / server integration and consumption of the data provided by the server.

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

    
asked by anonymous 02.10.2015 / 15:43

1 answer

4
  

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

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

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

About developing and consuming REST APIs

Angular itself provides resources for consumption of REST services, such as service % com and $http and there are a few PHP frameworks that can help your REST API developer such as Laravel and Slim Framework .

A very simple example of how to consume a REST API using ngResource

function HelloWorld($scope, $http) {
    $http.get('http://restservice.com:1233/HelloWorld').
        success(function(data) {
            $scope.hello = data;
       });
}
    
02.10.2015 / 17:56