Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Query parameters are one of the better known parameters. A query string is appended to the request URL with a leading "?" and then name/value pairs.A few examples

Tip
titleQuery Parameter Examples

Refer to the following links:

http://www.google.com/search?q=apache+wink

http://www.example.com/users?offset=100&numPerPage=20

In order to enable JAX-RS to read a query parameters, add a parameter to the resource method and annotate with @QueryParam:

...

If a HTTP GET request to "/example?q=abcd" is made, searchTerm would will have "abcd" as the value when invoked.

...

In a REST application, requests are stateless but although applications sometimes applications use Cookies for various reasons (i.e. put , such as adding some stateless resource viewing information without embedding it into the URL such as the maximum number of items to retrieve). The CookieParam annotation is used to easily get retrieve the information.

Code Block
@Path("/")
public class RootResource {
    @GET
    public Response invokeWithParameters(@CookieParam("max") String maximumItems) {
        if(userId == null) {
            return Response.status(Status.BAD_REQUEST).build();
        }
        return Response.ok(/* some entity here */).build();
    }
}