How to check HTTP request for OrientDB feature in AngularJS?

I have the following OrientDB function:



And it returns the following JSON result:



I need to do to get values "pass"

and "fail"

to use in my web page.

So far, I've been doing this with AngularJS:

success(function(data) {
    $ = data.result;

//    $scope.passCount = ;
//    $scope.failCount = ;



Currently, the error message "401 Unauthorized" appears. How can I verify the authenticity of a request?

And if possible, can anyone provide some advice on how to return the result to passCount

and failCount

from the JSON result?


source to share

1 answer

The OrientDB API documentation states that Basic HTTP authentication must be used to issue commands. This means that you must include the header Authorization

along with your request.

There are several ways to achieve this, here is an easier one. Use the config object parameter for $http.get

to set the request header:

function base64(str) {
    return btoa(unescape(encodeURIComponent(str)));

$http.get('http://...', {
    headers: { 'Authorization': 'Basic ' + base64(user + ':' + password) }


Make sure to move all your database logic into the Angular service so you can keep this code in one place and not pollute your controllers.

To make it even cleaner, you can look into $ http interceptors and write a request interceptor that adds a header for every HTTP call.

Regarding the JSON question: you can see that the result object contains an array with one element. Use indexing to get the actual record.

var result = data.result[0];
$scope.passCount = result.pass;
$scope.failCount =;


If you've written the service I mentioned, you can hide this implementation detail from your controller.

function getCount() {
    return $http.get(...).then(function (data) {
        var result = data.result[0];

        // the caller will only see this simpler object
        return { pass: result.pass, fail: };




All Articles