Module jpro.webapi

Class Response

java.lang.Object
com.jpro.webapi.server.Response

@Experimental public class Response extends Object
Represents a server response.

If no mime type is set, then a default mimetype based on the file extension will be used.

  • Constructor Details

    • Response

      public Response(byte[] body)
      Creates a response with the given body. This constructor sets the response as non-empty.
      Parameters:
      body - the response body
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Checks if the response is empty.
      Returns:
      true if the response is empty, false otherwise
    • getBody

      public byte[] getBody()
      Gets the body of the response.
      Returns:
      the response body, or null if the response is empty
    • getMimeType

      public String getMimeType()
      Gets the MIME type of the response.
      Returns:
      the MIME type, or null if not specified
    • empty

      public static Response empty()
      Creates an empty response.
      Returns:
      an empty response
    • of

      public static Response of(byte[] body)
      Creates a response with the given body.
      Parameters:
      body - the response body
      Returns:
      a response containing the specified body
    • of

      public static Response of(byte[] body, String mimeType)
      Creates a response with the given body and MIME type.
      Parameters:
      body - the response body
      mimeType - the MIME type of the response
      Returns:
      a response containing the specified body and MIME type