2

In java RESTfull service can I define two methods in same path differentiate by http calling method.

EG : first method using GET and Second one using POST

@GET
@Produces("application/pdf")
public Response getFile(@Context HttpServletRequest req,@PathParam("search") final String search,Map<Object, Object> input) {
....}

@Post
@Produces("application/pdf")
public Response getFile(@Context HttpServletRequest req,@PathParam("search") final String search) {
....}
rtruszk
  • 3,902
  • 13
  • 36
  • 53

2 Answers2

2

Annotation is just a decorator for the given method. The core principle is , it should not stop original structure of java classes. So it is perfectly legal to have multiple handler in single file.

Muthu
  • 540
  • 2
  • 5
  • 18
1

Yes, it is perfectly valid to have separate handlers for different methods at the same path.

Vlad
  • 10,602
  • 2
  • 36
  • 38