Query and path parameters
In our previous examples, we have been working with a RESTful web service to manage a single customer object. In real life, this would obviously not be very helpful. The common case is to develop a RESTful web service to handle a collection of objects (customers, in our example). To determine what specific object in the collection we are working with, we can pass parameters to our RESTful web services. There are two types of parameters we can use: query and path parameters.
Query parameters
We can add parameters to methods that will handle HTTP requests in our web service. Parameters decorated with the @QueryParam
annotation will be retrieved from the request URL.
The following example illustrates how to use query parameters in RESTful web services using Jakarta REST:
package com.ensode.jakartaeebook.queryparams.service; //imports omitted for brevity @Path("customer") public class CustomerResource { private static final Logger...