0

I am using Jersey Restful webservices. I have below web method to get the results.

@Path("/persons") public class PersonWS { private final static Logger logger = LoggerFactory.getLogger(PersonWS.class); @Autowired private PersonService personService; @GET @Path("/{id}") @Produces({MediaType.APPLICATION_XML}) public Person fetchPerson(@PathParam("id") Integer id) { return personService.fetchPerson(id); } 

}

Similarly how can i write a webmethod to delete a resource by id ?

Thanks!

1

3 Answers 3

1

You can use something like this:

 @DELETE @Path("/{id}") public void deletePerson(@PathParam("id") Integer id) { personService.deletePerson(id); } 
Sign up to request clarification or add additional context in comments.

2 Comments

Import Annotation from jersey.
You cant return with void method :)
0

You can create a delete method annotated with @DELETE and call it using delete http method in the rest client passing id.Check the below delete method for reference and you can change it as per your requirement.

 @DELETE @Path("/{id}") @Produces(MediaType.TEXT_PLAIN) public String deletePerson(@PathParam("id") Integer id) { //Your delete logic goes here return "Successfully deleted person info"; } 

1 Comment

Message is not required, HTTP STATUS CODE is enough.
0

Something like this

@DELETE @Path("/{id}") public void deletePerson(@PathParam("id") Integer id) { ... } 

with proper http status code

9.7 DELETE

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

More info: 3.1.2. @GET, @PUT, @POST, @DELETE, ... (HTTP Methods)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.