Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Web Service - Dynamic Query Parameters

I have a requirement to send dynamic query parameters to REST web service GET method [as shown below].

host:port/app?field1=XXX&value1=VVV&field2=XXX&value2=XXX ....

The consumer can send parameters up to fieldn and valuen. Each field maps to the value.

With this type of requirement, I can't code a finite set of QueryParams on the server side method.

Is there any type of REST library that supports this? I checked RESTEasy and Jersey, and they both don't seem to support this [as far as I checked].

Thanks.

like image 457
Arav Vijay Avatar asked Oct 24 '25 02:10

Arav Vijay


1 Answers

Use UriInfo.getQueryParameters(), as following:

@GET
@Path("/foo")
@Produces(MediaType.APPLICATION_JSON)
public Response foo(@Context UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
    ...
}

It returns a MultivaluedMap. Then just iterate over it.

like image 183
cassiomolin Avatar answered Oct 27 '25 00:10

cassiomolin