Class DiscordWebRequest

java.lang.Object
discord4j.rest.request.DiscordWebRequest

public class DiscordWebRequest extends Object
Template encoding all the needed information to make an HTTP request to Discord.
  • Constructor Details

    • DiscordWebRequest

      public DiscordWebRequest(Route route, Object... uriVars)
      Create a new DiscordWebRequest template based on a Route and its compiled URI.
      Parameters:
      route - the API resource targeted by this request
      uriVars - the values to expand each template parameter
  • Method Details

    • copy

      public DiscordWebRequest copy()
      Create a new instance using the values from this one.
      Returns:
      a new request
    • getRoute

      public Route getRoute()
      Return the API endpoint targeted by this request.
      Returns:
      the Route of this DiscordWebRequest
    • getCompleteUri

      public String getCompleteUri()
      Return the compiled URI of this request.
      Returns:
      the compiled URI, containing the actual path variables
    • getBody

      @Nullable public Object getBody()
      Return the body of this request, if present.
      Returns:
      the body of this request, or null if this request carries no HTTP body
    • getQueryParams

      @Nullable public Multimap<String,Object> getQueryParams()
      Return the query parameters saved in this request, if present.
      Returns:
      a map representing query parameters, or null if none are defined
    • getHeaders

      @Nullable public Map<String,Set<String>> getHeaders()
      Return the request headers, if present.
      Returns:
      a map representing HTTP headers, or null if none are defined
    • getAuthorizationScheme

      @Nullable public AuthorizationScheme getAuthorizationScheme()
    • getAuthorizationValue

      @Nullable public String getAuthorizationValue()
    • body

      public DiscordWebRequest body(Object body)
      Set the given synchronous Object as the body for the request.
      Parameters:
      body - the object to set as request body
      Returns:
      this request
    • query

      public DiscordWebRequest query(String key, Object value)
      Add the given name and value as a request query parameter.
      Parameters:
      key - the query parameter name
      value - the query parameter value
      Returns:
      this request
    • query

      public DiscordWebRequest query(Map<String,Object> params)
      Adds the given names and values as request query parameters.
      Parameters:
      params - a map of query parameter names to values
      Returns:
      this request
    • query

      public DiscordWebRequest query(Multimap<String,Object> params)
      Add the given names and values as request query parameters.
      Parameters:
      params - a map of query parameter names to values
      Returns:
      this request
    • header

      public DiscordWebRequest header(String key, String value)
      Adds the given key and value to the headers of this request.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      this request
    • optionalHeader

      public DiscordWebRequest optionalHeader(String key, @Nullable String value)
      Adds the given key and value to the headers of this request if and only if value is not null.
      Parameters:
      key - the header key
      value - the header value
      Returns:
      this request
    • bearerAuth

      public DiscordWebRequest bearerAuth(String accessToken)
      Use the given token as authentication value using the Bearer prefix.
      Parameters:
      accessToken - the bearer token to use
      Returns:
      this request
    • basicAuth

      public DiscordWebRequest basicAuth(String base64EncodedValue)
      Use the given value as basic authentication.
      Parameters:
      base64EncodedValue - the base64 encoded value to use
      Returns:
      this request
    • unauthenticated

      public DiscordWebRequest unauthenticated()
      Use no authorization mechanism with this request.
      Returns:
      this request
    • exchange

      public DiscordWebResponse exchange(Router router)
      Exchange this request through the given Router.
      Parameters:
      router - a router that performs this request
      Returns:
      the result of this request
    • getDescription

      public String getDescription()
    • toString

      public String toString()
      Overrides:
      toString in class Object