RequestQuery
The {@link oajr.RequestQuery} object is the API for accessing the GET query parameters of an HTTP request.
It can be accessed by passing it as a parameter on your REST Java method:
@RestMethod(...)
public Object myMethod(RequestQuery query) {...}
@RestMethod(...)
public Object myMethod(RequestQuery query) {
// Get query parameters converted to various types.
int p1 = query.get("p1", 0, int.class);
String p2 = query.get("p2", String.class);
UUID p3 = query.get("p3", UUID.class);
}
An important distinction between the behavior of this object and HttpServletRequest.getParameter(String) is
that the former will NOT load the body of the request on FORM POSTS and will only look at parameters
found in the query string.
This can be useful in cases where you're mixing GET parameters and FORM POSTS and you don't want to
inadvertently read the body of the request to get a query parameter.
Some important methods on this class are:
- {@link oajr.RequestQuery} extends LinkedHashMap<String,String[]>
- {@link oajr.RequestQuery#get(String,Class) get(String,Class)} - Get query parameter value converted to a POJO.
- {@link oajr.RequestQuery#get(String,Type,Type...) get(String,Type,Type)} - Get query parameter value converted to a map or collection of POJOs.
- {@link oajr.RequestQuery#getString(String,String) getString(String,String)} - Get query parameter value as a simple string.
- {@link oajr.RequestQuery#getInt(String,int) getInt(String,int)} - Get query parameter value as an integer.
- {@link oajr.RequestQuery#getBoolean(String,boolean) getBoolean(String,boolean)} - Get query parameter value as a boolean.
- {@link oajr.RequestQuery#addDefault(String,Object) addDefault(String,Object)} - Programmatically set a default value for a query parameter.
- {@link oajr.RequestQuery#getSearchArgs() getSearchArgs()} - Returns query parameter search arguments.
- {@link oaj.http.annotation.Query}
- {@link oaj.http.annotation.HasQuery}