Passing undefined query parameters with a RESTful URL and reading them in RESTEasy

I have a requirement to create a RESTful Service using RESTEasy. Clients can call this shared service with any number of request parameters that they would like. My REST code should be able to read these Request Parameters in some way. For example, if I have a book search service, clients can make the following calls.

http://domain.com/context/rest/books/searchBook?bookName=someBookName
http://domain.com/context/rest/books/searchBook?authorName=someAuthor& pubName=somePublisher
http://domain.com/context/rest/books/searchBook?isbn=213243
http://domain.com/context/rest/books/searchBook?authorName=someAuthor

I need to write a service class as described below.

@Path("/books")
   public class BookRestService{

    // this is what I currently have, I want to change this method to in-take all the 
    // dynamic parameters that can come
    @GET
    @Path("/searchBook")
    public Response searchBook(@QueryParam("bookName") String bookName,@QueryParam("isbn") String isbn) {

     // fetch all such params
     // create a search array and pass to backend

    }

    @POST
    @Path("/addBook")
    public Response addBook(......) {
    //....
     }
    }

Sorry for the poor format (I could not understand how code formatting works in this editor!). As you can see, I need to change the searchBook () method to execute any number of query parameters.

I saw a similar post here, but could not find the right solution.

URL- RESTful ?

- , ?

+3
2

DTO, . , 4 .

  • (bookName)
  • ( )
  • (pubName)
  • ISBN (isbn)

DTO, , , :

public class CriteriaDTO{

  @QueryParam("isbn")
  private String isbn;
.
.

Other getter and setters of other properties

}

:

@GET
@Produces("application/json")
@Path("/searchBooks")
public ResultDTO search(@Form CriteriaDTO dto){
}

URL- CriteriaDTO isbn:

your.server.ip: /URL/Mapping/searchBooks = 123456789 ISBN & pubName =

+7

: bean GET?

(UriInfo). , , .

+1

All Articles