I am creating a REST service and I have the following API -
@PUT
@Path("/delete/{teamName}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response delete(@PathParam("teamName")String teamName) {
if (db.delete(teamName)) {
return Response.status(200).build();
}
return Response.status(400).build();
}
This API accepts a PathParam to delete a teamname. It is a PUT call.
My questions are -
Is it a good practice to use
@PathParamsin a PUT call?What are the advantages and disadvantages?
@PathParamsignifies the identifier is variable.@Consumesannotation specifies what kind of data the server expects in the body of the request (i.e. not in the URL or query parameters). If your endpoint expects only@PathParamthen you don't need@Consumessince you're not reading whatever is in the body anyway.