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 Summary

    Constructors
    Constructor
    Description
    Response(byte[] body)
    Creates a response with the given body.
    Response(byte[] body, int statusCode)
    Creates a response with the given body and status code.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Response
    Creates an empty response.
    byte[]
    Gets the body of the response.
    Gets the MIME type of the response.
    int
    Gets the HTTP status code of the response.
    boolean
    Checks if the response is empty.
    static Response
    of(byte[] body)
    Creates a response with the given body.
    static Response
    of(byte[] body, String mimeType)
    Creates a response with the given body and MIME type.
    static Response
    of(byte[] body, String mimeType, int statusCode)
    Creates a response with the given body, MIME type, and status code.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • Response

      public Response(byte[] body, int statusCode)
      Creates a response with the given body and status code. This constructor sets the response as non-empty.
      Parameters:
      body - the response body
      statusCode - the HTTP status code
  • 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
    • getStatusCode

      public int getStatusCode()
      Gets the HTTP status code of the response.
      Returns:
      the HTTP status code
    • 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
    • of

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