Mishi
Mishi

Reputation: 676

how to pass query parameter for get method in angularjs

I have rest API built in WSO2 ESB. This is my request in service for POST method.

createUser: function(aUser) {
            var myCreateUserRequest =  {
                       "User":    {
                          "UserName": aUser.Username,
                          "UserPassword": aUser.Password,
                          "OrganizationId": aUser.OrgId,
                          "UserStatus": "Active", }}          
            //API Call
            var promise = $http.post(API_URL,myCreateUserRequest,REQUEST_HEADER).then(
            function(aCreateUserResponse) { 
                return [aCreateUserResponse.data.CreateUserResponse.Result.ResponseCode,''];
            });
             return promise; },

NOW similarly I want to pass only 2 parameter to GET a user i.e UserName and Organization id. How can I do that in angular js? What I have implemented so far is:

getUser: function() {
            params =  {"UserName": aUser.Username, "OrganizationId": aUser.OrgId}         
            //API Call
            var promise = $http.get(API_URL,params,REQUEST_HEADER).then(
            function(aGetUserResponse) { 
                return [aGetUserResponse.data.GetUserResponse.Result,''];
            });
             return promise; },

Is this is the correct way to do else how can I do this?

Upvotes: 1

Views: 589

Answers (1)

Andiih
Andiih

Reputation: 12413

No, this isn't correct, as POST has a data parameter, GET does not (because there is no body in Get request). Docs

In order to pass those parameters, you need to add them to the URL as querystrings

Upvotes: 1

Related Questions