Hi,

I am just new in Angular JS. Now involved in creating one secured 
application that will consume RESTservices (written in Java resteasy) from 
server application. I'm able to call RESTful service using *$http.jsonp *but 
I don't know whether it is how much secured. Therefore I want to use POST 
method.

I was trying to call using *$http.post* but it is not known to me how to 
call service along with passing values to it. 

Here is code snippet for my REST Service as given below -

@Path("/GatewayService")
public class GatewayServiceImpl implements GatewayService {

@PersistenceContext 
private EntityManager entityManager;
 @Override
@Path("/fetchDetails/{accountno}")     
*@POST*
@Consumes("application/json")
@Produces({"application/json"}) 
 public WbWebGenericEntity fetchDetails(String accountno) {
WbWebGenericEntity genericEntity = new WbWebGenericEntity(); 
try { 
genericEntity.setAccountnumber("8902688190");        /// some hard coded 
values are set into the property
genericEntity.setAccountname("JAYANTA PRAMANIK");
} 
catch(Exception e){
e.printStackTrace();
}
/*catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
return genericEntity;
}


*And here is my Angular JS call to this REST service -*


/*
 *  -----* Controller.js*
 *  ----- Required dependencies are injected into the controller’s signature
 */
function MyAccountController($scope, $http, GenericService){

    $scope.findAccountInfo = function () {
        $scope.removeFetchedData();
        $scope.getAccountInfo();         //// Calling Service from this 
function
        console.log($scope.fetchedData);
    }

    $scope.getAccountInfo = function () {
        
GenericService.getAcctInfo('8902688190').success(function(summaryDetail){
            alert(summaryDetail);
        })
    }

    $scope.removeFetchedData = function () {
        alert('removeFetchedData --------');
        $scope.fetchedData=[];
    }

}

/*
 *  -------- Services.js
 * --------  All required services are written here
 */

//ROUTING WITH IN INDEX PAGE
var myModule = angular.module('myModule', [])
    .config(['$routeProvider', '$locationProvider', function 
($routeProvider, $locationProvider) {
        $routeProvider.
            when('/videos', {templateUrl: 'myPages/Welcome.html'}).
            when('/videos/logout', {templateUrl: 'login.html'}).
            *. . .*
*            . . . . .*

            otherwise({redirectTo: '/videos'});

    }]);


////---- WRITING SERVICE FACTORY TO CONSUME WEB SERVICE ---- ////

myModule.factory('GenericService', ['$http', function($http) {
    var service = {
        getAcctInfo: function (acctno) {
            alert("Here inside factory method");
            console.log("Account No : " + acctno);
            var accountInfo = {};
            accountInfo.accountno=acctno;

            $http({method: 'POST', url: 
'http://localhost:8080/demoapp/service/GatewayService/'}).
                success(function(data, status, headers, config) {
                           /// some actions taken
                }).
                error(function(data, status, headers, config) {
                          //// Some messages logged
                });
        }
    };
    return service;
}]);


Please any body help me. I need this REST service (as above) to call from 
Angular JS using *$http.post* 
Is there any other mechanism like *$resource *to call the REST service ? If 
yes, please share the code sample if I want to call above REST service.

Thanks in advance.

Jayanta Pramanik

















-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to