Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Latest commit

 

History

History
27 lines (22 loc) · 852 Bytes

response.md

File metadata and controls

27 lines (22 loc) · 852 Bytes

Response

Response<T> is an optional wrapper for the return type of route handlers. Use it when you want to control additional parameters of the service reply like setting a different status code or adding headers.

Examples:

Response<String> handle(RequestContext requestContext) {
  String s = stringResponse();
  return Response.forPayload(s)
      .withHeader("X-Payload-Length", String.valueOf(s.length()));
}
Response<String> handle(RequestContext requestContext) {
  String arg = requestContext.request().getParameter("arg");
  if (arg == null || arg.isEmpty()) {
    return Response.forStatus(
        Status.BAD_REQUEST.withReasonPhrase("Mandatory query parameter 'arg' is missing"));
  }

  return Response.forPayload("Your " + arg + " is valid");
}