AngularJS - Can not find API driver

0

Colleagues, I have the following problem: when wanting to access from a controller js to an API controller just to bring a list of users, the console sends me error 404.

Service that accesses the corresponding controller, passing as parameter the name of the same (apiName)

cobra.app.factory('ResourceService', function ($resource) {
var prefix = '/FLOTA/api/';

function _getResource(apiName) {
    var idParam = (apiName.indexOf(":id") >= 0 ? "" : "/:id");
    var resource = $resource(apiName + idParam, { id: '@id' },
    {
        queryp: { method: 'PUT' },
        update: { method: 'PUT' },
        save: { method: 'POST', params: { id: null } },
        getp: { method: 'POST', params: { id: null } }
    });
    return resource;
}

function getResource(apiName) {
    return _getResource(prefix + apiName);
}

return {
    resource: getResource
}
});

When you indicate that you access the "Users" API driver, it is where you launch the 404

cobra.app.controller('usersListController', function ($scope, LoadingService, UtilityService, ResourceService, NotificationService) {
$scope.collection = [];
$scope.displayedCollecion = [];
$scope.headers = {
    username: { name: 'Usuario', visible: true },
    fullname: { name: 'Nombre', visible: true }
};

var restAPI = ResourceService.resource('Users');

var errorCallback = function (result) {
    LoadingService.hideLoading();
    NotificationService.error(result);
}

var successGetCallback = function (result) {
    $scope.collection = result;
    $scope.displayedCollecion = [].concat(result);

    LoadingService.hideLoading();
}

var getCollection = function () {
    restAPI.query(successGetCallback, errorCallback);
}

angular.element(document).ready(function () {
    getCollection();
});
});

Any guidance is appreciated!

    
asked by Paulo Urbano Rivera 15.02.2017 в 17:07
source

1 answer

0

A possible error may be that when you send the URL to the service $ resources you do it only partially (" / FLOAT / api / Users ") so if you are in " www .tudominio.com "the request is going to do the URL" www.yourdomain.com/FLOTA/api/Users ", you could try putting the full URL to make sure it is coming to the right address.

I also see that the query function that is the one you are using is being done as PUT when a request that tries to get a list and in which a payload is not sent normally should be > GET but that depends on how the API you are consuming is designed. Make sure you're using the correct method.

I hope it helps you. Greetings

    
answered by 16.02.2017 в 03:55