rish rish - 1 month ago 14
reST (reStructuredText) Question

Java REST call using angularjs with param value

I am trying to make REST call in java using angularjs-

Java Code:-

@GET
@Path("/getData/{id}")
@Produces(MediaType.TEXT_PLAIN)
public static String getData(@PathParam("id") String id) {
//Operation
}


AngularJs REST call-

var response = $http.get('/projName/rest/get/getData', {params: {id: id}});


But it's giving me exception-


org.jboss.resteasy.spi.NotFoundException: Could not find resource for full path:

Answer

The error is caused by the fact, that you're trying to access different endpoint. Your endpoint listens for requests like:

projName/rest/get/getData/{id}
//e.g.
projName/rest/get/getData/1

but you're calling:

projName/rest/get/getData?id={id}
projName/rest/get/getData?id=1

Your code should be:

var response = $http.get('/projName/rest/get/getData/' + id);

@GET
@Path("/getData/{id}")
@Produces(MediaType.TEXT_PLAIN)
public static String getData(@PathParam String id) {
        //Operation 
}