Manoj Majumdar
Manoj Majumdar

Reputation: 525

Get Json object passed in $http.put request

I am a newbie to angularjs. I am trying to send a json object in $http.put request as follows:

function LoginCtrl($http){
this.login = function(){
  var self = this;
        self.user = {
            username: this.username,
            password: this.password
        }
    $http.put('http://localhost:8086/app/login',self.user).then(function 
successCallback(response) {
      }, function errorCallback(response) {
      })
}
}

I just want to get this json object in Rest api, the code of which is as follows: @Path("/app") public class LoginResource {

public LoginResource() {
}

@PUT
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
public Response getUserByName() {
    return Response.status(Response.Status.ACCEPTED).build();
}

What parameters i need to pass to this getUserByName api?. I am using dropwizard

Also if somebody could tell how to set the index.html page as the starting page in jetty server config.

Upvotes: 0

Views: 1420

Answers (2)

P J
P J

Reputation: 70

http.put(url, JSON.stringify(self.user), function (err, response) 
{
    // do something here
}

Upvotes: 0

vilzu
vilzu

Reputation: 26

First, in your Dropwizard(Jersey) backend define your input

public Response getUserByName(User user) { ...

Then you can map your JSON to an entity like this:

public class User {
   @JsonProperty("name") 
   private String name; }

In angularJS pass the Json object as a request payload in $http.PUT(uri,<JsonObject>)

Upvotes: 1

Related Questions