Class BackendRequest

java.lang.Object
net.streamlinecloud.mc.common.utils.BackendRequest

public class BackendRequest extends Object
BackendRequest is a utility class for making HTTP requests to the backend.
  • Constructor Details

    • BackendRequest

      public BackendRequest()
  • Method Details

    • fetch

      public BackendRequest fetch()
      Fetches data from the backend server using the specified method and URL. This method is a shorthand for calling fetch(Consumer) with an empty consumer. This method is useful for simple requests where no further processing is needed, the response is not needed or to store the response data and use it in another method or class.
    • withBody

      public BackendRequest withBody(String body)
      Sets the request body.
      Parameters:
      body - the request body
      Returns:
      this instance.
    • withHeaders

      public BackendRequest withHeaders(Map<String,String> headers)
      Sets the request headers.
      Parameters:
      headers - the request headers
      Returns:
      this instance.
    • setType

      public BackendRequest setType(@NonNull @NonNull BackendRequest.RestType type)
      Sets the request method.
      Parameters:
      type - the request method
      Returns:
      this instance.
      See Also:
    • setAuth

      public BackendRequest setAuth(boolean auth)
      Sets whether to use authentication.
      If set to true, the request will include an authorization header with a token.
      If set to false, the request will not include an authorization header.
      This should be set to false for public endpoints.
      For most use cases it's not required to change auth to false
      Parameters:
      auth - true to use authentication, false to not use authentication - default is true
      Returns:
      this instance.
    • setUrl

      public BackendRequest setUrl(@NonNull @NonNull String url)
      Sets the request URL.
      Parameters:
      url - the request URL
      Returns:
      this instance.
    • setApplicationType

      public BackendRequest setApplicationType(BackendRequest.ApplicationType applicationType)
      Sets the request method.
      Parameters:
      applicationType - the request application type
      Returns:
      this instance.
      See Also:
    • fetch

      public void fetch(Consumer<BackendRequest> consumer)
      Fetches data from the backend server using the specified method and URL.
      Parameters:
      consumer - a consumer that accepts the BackendRequest instance as an argument