How call rest api in angularjs which returns boolean

1.2k Views Asked by At

I have a rest api which returns true/false, i called my rest api in postman and it works and it returns true or false. I need to call this service in angularjs, what change should i do in my angular js to make it return true/false, beacause now it returnsobjewct object.

function checkIsActive() {            
    return $resource('http://localhost:8080/myservice/v1/testService').query().$promise;
}
1

There are 1 best solutions below

2
georgeawg On BEST ANSWER

For APIs that return boolean values, use the $http service:

function checkIsActive() {            
    return $http.get('http://localhost:8080/myservice/v1/testService');
}

The $resource service returns arrays for the .query action method and objects for the .get action method.


when i have console.log(myService.checkIsActive()); then it print [object Object] still it does not return boolean.

Keep in mind that the service returns a promise from which the data needs to be extracted:

var promise = myService.checkIsActive();
promise.then(function(response) {
    console.log(response.data);
};