-2

URI looks like /api/v2/Employee?filter[search_key]=1234 I want to define REST API method for above URI but I am not getting how to consume [search_key]

    @Path("/Employee")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public interface EmployeeServices {
    
    
    @GET
    public List<Employee> searchEmployee(@QueryParam("filter") String filter);

}

Jockey
  • 1
  • 1

1 Answers1

0

Please clarify your question.

This is how you can consume a path parameter provided in the URL to your application:

@GET
@Path("/Employee/{filter}")
@Produces({MediaType.APPLICATION_JSON})
public List<Employee> searchEmployee(@PathParam("filter") String filter){
   //your code
}

If you are trying to do some actual back end processing here (making a controller class), than this should rather be a class than an interface.

If you really intend to use a @QueryParam then check this post: When to use @QueryParam vs @PathParam

Babi
  • 103
  • 1
  • 7
  • thnaks my question is How to write method signature for above url brackets part [] – Jockey Jul 21 '20 at 13:37
  • "filter" in this answer can be replaced with anything. You just need to get the same QueryParam / PathParam in the signature as the one in your URL. "[" is a general delimiter that you cannot use in your URLs without encoding it. The RFC 3986 defines the following set of reserved characters that can be used as delimiters. Hence, they require URL encoding: : / ? # / [ ] / @ ! $ & ' ( ) * + , ; = Check URL encoding of chars here: https://www.urlencoder.org/ – Babi Jul 21 '20 at 16:03