@BeanParam

We can create a bean and annotate with @BeanParam. The properties on the bean default to being query parameters.

We typically do this when we have a set of query parameters that are common / shared across a number of endpoints.

public class CommonParams {

  public Long firstRow;
  public Long maxRows;
  public String sortBy;
  public String filter;
}

We annotate the bean with @BeanParam

@Get("search/:type")
List<Cat> findCats(String type, @BeanParam CommonParams params) {

  ...
}

The generated code for the above is:

ApiBuilder.get("/cats/search/:type", ctx -> {
  ctx.status(200);
  String type = ctx.pathParam("type");
  CommonParams params =  new CommonParams();
  params.firstRow = toLong(ctx.queryParam("firstRow"));
  params.maxRows = toLong(ctx.queryParam("maxRows"));
  params.sortBy = ctx.queryParam("sortBy");
  params.filter = ctx.queryParam("filter");

  ctx.json(controller.findCats(type, params));
});

@Form

@BeanParam and @Form are very similar except with @Form beans the properties default to form parameters and with @BeanParam they default to query parameters.

We could use @BeanParam with forms but then we need to put @FormParam on each of the form parameter properties (like JAX-RS but we start to suffer from annotation overload).

JAX-RS @BeanParam

Our @BeanParam is virtually the same as JAX-RS @BeanParam except the properties default to being query parameters (where as with JAX-RS we need to annotate each of the properties). We can do this because we have @Form and "Form beans".

BeanParam beans with @Header, @Cookie properties

The properties on a "bean" default to being query parameters. We put @Header or @Cookie on properties that are instead headers or cookies.

public class CommonParams {

  public Long firstRow;
  public Long maxRows;
  public String sortBy;
  public String filter

  @Header
  public String ifModifiedSince;

  @Cookie
  public String myState;
}