0

I'm listing users with:

/api/users/

I'd like to list users who are admins by calling:

/api/users/admins

As trivial as it may seem, I can't find a way to do this.

gkpo
  • 2,623
  • 2
  • 28
  • 47
  • Which ways did you find that didnt work for you? You also can use [slim router](http://www.slimframework.com/) – B001ᛦ Oct 08 '15 at 14:16

2 Answers2

0

I do not know which programming language you are using, but I'm going to give you an example using PHP Laravel, and AngularJS.

API

Route::get('/api/users', function ()
{
    $users = App\User::all();
    return $users;
});

Route::get('/api/users/admin', function ()
{
    $users = App\User::where('admin', true)->get();
    return $users;
});

FRONT

angular.module('app', [])
.service('api', ['$http', function ($http) {
  function getUsers() {
    return $http.get('/api/users');
  }
  function getAdminUsers() {
    return $http.get('/api/users/admin');
  }
  this.getUsers = getUsers;
  this.getAdminUsers = getAdminUsers;
}])
.controller('UserCtrl', ['$scope', 'api', function ($scope, api) {
  $scope.users = [];
  $scope.adminUsers = [];
  api.getUsers()
    .then(function success(response) {
      $scope.users = response.data;
    }, function error(response) {
    });
    api.getAdminUsers()
    .then(function success(response) {
      $scope.adminUsers = response.data;
    }, function error(response) {
    });
}]);
Emmanuel Lozoya
  • 128
  • 2
  • 10
0

Sorry about the lack of details in my question. I was actually asking the question about the angular-restmod module.

Here's what I did in the end:

module.factory('CustomMethods', ['restmod', 'RMUtils', function CustomMethodsMixin(restmod, RMUtils) {
  return restmod.mixin(function() {
    this.define('Model.$customCollection', function(_url, params) {
      var original = this;
      return this.$collection(params, {
        $urlFor: function() {
          return RMUtils.joinUrl(original.$url(), _url);
        }
      });
    });
    return this;
  });
}]);

And expose all my api to it:

restmodProvider.rebase('CustomMethods')
gkpo
  • 2,623
  • 2
  • 28
  • 47