A task in my javascript involves making an ajax post request to one of my JAX-RS functions. Here is a snippet of the code:
var postPackingListRequest = $http({
method: "post",
url: "/rest/v1/submit",
data: $scope.items
});
In the JAX-RS method, I am trying to retrieve the variable $scope.items
that was passed. I am aware of how to get path params from the URL like this:
public Response getPathParams(@QueryParam("id") int id) {
However, I am unsure about how to access the data sent in the body of the request.
Thank you for any assistance.
UPDATE
@POST
@Path("submit")
@Consumes(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = 201, response = Response.class) })
@Produces("application/json")
public Response submitPackingList(TestUser testUser) {
}
public class TestUser {
public String id;
public String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
When attempting to send a request with TestUser data, I encounter an HTTP 400 error. Here is the format of the request being sent:
var postPackingListRequest = $http({
method: "post",
url: "/rest/v1/submit",
data: "{'user':'1', 'name':james}"
});