Class ResponseBuilder


  • public class ResponseBuilder
    extends java.lang.Object
    • Method Detail

      • setMimeType

        public ResponseBuilder setMimeType​(java.lang.String mimeType)
        Set MIME Type of the Response.
        Parameters:
        mimeType - MIME type of the Response https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
        Returns:
        this builder.
        See Also:
        for common MIME types.
      • setStatus

        public ResponseBuilder setStatus​(int code)
        Set HTTP Status code.

        Default status code is 200 (OK) if not set.

        Parameters:
        code - 1xx, 2xx, 3xx, 4xx, 5xx, https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
        Returns:
        this builder.
      • setHeader

        public ResponseBuilder setHeader​(java.lang.String header,
                                         java.lang.Object value)
        Set HTTP Response header.
        Parameters:
        header - Key of the header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
        value - Value for the header.
        Returns:
        this builder.
      • redirectTo

        public ResponseBuilder redirectTo​(java.lang.String url)
        Utility method for building redirects.
        Parameters:
        url - URL to redirect the client to with 302 Found.
        Returns:
        https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location
      • setContent

        public ResponseBuilder setContent​(java.lang.String utf8String)
      • setContent

        public ResponseBuilder setContent​(java.lang.String content,
                                          java.nio.charset.Charset charset)
      • setJSONContent

        public ResponseBuilder setJSONContent​(java.lang.Object objectToSerialize)
        Set content as serialized JSON object.
        Parameters:
        objectToSerialize - Object to serialize into JSON with Gson. If the object is a String it is assumed to be valid JSON.
        Returns:
        this builder.
      • setJSONContent

        public ResponseBuilder setJSONContent​(java.lang.String json)