1

I am trying to query a REST API which I have hosted locally and this should work something as follows:

http://localhost:51608/api/[email protected]

That request works and it returns a User Object with an AccessLevel property. Now I have an angular application and want to query that URL using Angular Resource. I have something as follows but the URL is not being built properly.

(function () {
    "use strict";

    angular
        .module("common.services")
        .factory("userRoleResource",
                ["$resource",
                 "appSettings",
                    userRoleResource])

    function userRoleResource($resource, appSettings) {
        return $resource(appSettings.serverPath + "/api/UserRole:email", { email: '@email'});
    }
})();

I am querying the above as follows:

userRoleResource.query({ email: vm.userData.email },
   function (data) {
      vm.userData.accessLevel = data.AccessLevel;
});

But this is generating the request as follows:

http://localhost:51608/api/[email protected] instead of http://localhost:51608/api/UserRole?email:[email protected]

What's wrong here?

1
  • function userRoleResource($resource, appSettings) { return $resource(appSettings.serverPath + "/api/UserRole?email=:email", { email: '@email'}); } Commented Apr 19, 2016 at 14:53

2 Answers 2

1

As per $resource current working it does replace :email with the email parameter you provided to $resource object. You can have encoded : in a place like %3A

function userRoleResource($resource, appSettings) {
    return $resource(appSettings.serverPath + "/api/UserRole%3A:email", { email: '@email'});
}
Sign up to request clarification or add additional context in comments.

Comments

0

Why don't you just format your string like :

return $resource(appSettings.serverPath + "/api/UserRole?email:" + email});

1 Comment

Are you considering to create $resource object each time when you call method? I don't think so that would be an good idea to go..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.