Class BaseRequest<T>

java.lang.Object
com.microsoft.graph.http.BaseRequest<T>
Type Parameters:
T - the response class
All Implemented Interfaces:
IHttpRequest
Direct Known Subclasses:
BaseReferenceRequest, BaseWithReferenceRequest, BatchRequest, CustomRequest, PrimitiveRequest

public abstract class BaseRequest<T> extends Object implements IHttpRequest
An HTTP request.
  • Field Details

    • REQUEST_STATS_HEADER_VALUE_FORMAT_STRING

      public static final String REQUEST_STATS_HEADER_VALUE_FORMAT_STRING
      The request stats header value format string
      See Also:
      Constant Field Values
    • queryOptions

      protected final List<QueryOption> queryOptions
      The query options for this request
    • functionOptions

      protected final List<FunctionOption> functionOptions
      The function options for this request
  • Constructor Details

    • BaseRequest

      public BaseRequest(@Nonnull String requestUrl, @Nonnull IBaseClient<?> client, @Nullable List<? extends Option> options, @Nonnull Class<? extends T> responseClass)
      Creates the request
      Parameters:
      requestUrl - the URL to make the request against
      client - the client which can issue the request
      options - the options for this request
      responseClass - the class for the response
  • Method Details

    • getRequestUrl

      @Nullable public URL getRequestUrl()
      Gets the request URL
      Specified by:
      getRequestUrl in interface IHttpRequest
      Returns:
      the request URL
    • getHttpRequest

      @Nullable public <requestBodyType,​ responseType,​ nativeRequestType> nativeRequestType getHttpRequest(@Nullable requestBodyType serializedObject) throws ClientException
      Returns the Request object to be executed
      Specified by:
      getHttpRequest in interface IHttpRequest
      Type Parameters:
      requestBodyType - the type of the serialized object
      responseType - the type of the response
      nativeRequestType - type of a request for the native http client
      Parameters:
      serializedObject - the object to serialize at the body of the request
      Returns:
      the Request object to be executed
      Throws:
      ClientException
    • getHttpMethod

      @Nullable public HttpMethod getHttpMethod()
      Gets the HTTP method
      Specified by:
      getHttpMethod in interface IHttpRequest
      Returns:
      the HTTP method
    • getHeaders

      @Nullable public List<HeaderOption> getHeaders()
      Gets the headers
      Specified by:
      getHeaders in interface IHttpRequest
      Returns:
      the headers
    • addHeader

      public void addHeader(@Nonnull String header, @Nullable String value)
      Adds a header to this request
      Specified by:
      addHeader in interface IHttpRequest
      Parameters:
      header - the name of the header
      value - the value of the header
    • setUseCaches

      public void setUseCaches(boolean useCaches)
      Sets useCaches parameter to cache the response
      Specified by:
      setUseCaches in interface IHttpRequest
      Parameters:
      useCaches - the value of useCaches
    • getUseCaches

      public boolean getUseCaches()
      Gets useCaches parameter
      Specified by:
      getUseCaches in interface IHttpRequest
      Returns:
      the value of useCaches
    • sendAsync

      @Nonnull protected <T1> CompletableFuture<T> sendAsync(@Nonnull HttpMethod method, @Nullable T1 serializedObject)
      Sends this request
      Type Parameters:
      T1 - the type of the serialized body
      Parameters:
      method - the HTTP method
      serializedObject - the object to serialize as the body
      Returns:
      a future with the result
    • send

      @Nullable protected <T1> T send(@Nullable HttpMethod method, @Nullable T1 serializedObject) throws ClientException
      Sends this request
      Type Parameters:
      T1 - the type of the serialized body
      Parameters:
      method - the HTTP method
      serializedObject - the object to serialize as the body
      Returns:
      the response object
      Throws:
      ClientException - an exception occurs if there was an error while the request was sent
    • getQueryOptions

      @Nullable public List<QueryOption> getQueryOptions()
      Gets the query options for this request
      Returns:
      the query options for this request
    • getFunctionOptions

      @Nullable public List<FunctionOption> getFunctionOptions()
      Gets the function options for this request
      Returns:
      the function options for this request
    • getOptions

      @Nullable public List<Option> getOptions()
      Gets the full list of options for this request
      Specified by:
      getOptions in interface IHttpRequest
      Returns:
      the full list of options for this request
    • addQueryOption

      public void addQueryOption(@Nonnull QueryOption option)
      Adds a query option
      Parameters:
      option - the query option to add
    • addFunctionOption

      public void addFunctionOption(@Nonnull FunctionOption option)
      Adds a function option
      Parameters:
      option - the function option to add
    • addExpandOption

      protected void addExpandOption(@Nonnull String value)
      Sets the expand clause for the request
      Parameters:
      value - the expand clause
    • addFilterOption

      protected void addFilterOption(@Nonnull String value)
      Sets the filter clause for the request
      Parameters:
      value - the filter clause
    • addOrderByOption

      protected void addOrderByOption(@Nonnull String value)
      Sets the order by clause for the request
      Parameters:
      value - the order by clause
    • addSelectOption

      protected void addSelectOption(@Nonnull String value)
      Sets the select clause for the request
      Parameters:
      value - the select clause
    • addTopOption

      protected void addTopOption(int value)
      Sets the top value for the request
      Parameters:
      value - the max number of items to return
    • addSkipOption

      protected void addSkipOption(int value)
      Sets the skip value for the request
      Parameters:
      value - of the number of items to skip
    • addSkipTokenOption

      protected void addSkipTokenOption(@Nonnull String skipToken)
      Add Skip token for pagination
      Parameters:
      skipToken - - Token for pagination
    • addCountOption

      protected void addCountOption(boolean value)
      Adds the count query string value for the request
      Parameters:
      value - - Wheter to return the count or not
    • setHttpMethod

      public void setHttpMethod(@Nonnull HttpMethod httpMethod)
      Sets the HTTP method
      Parameters:
      httpMethod - the HTTP method
    • withHttpMethod

      @Nullable public IHttpRequest withHttpMethod(@Nonnull HttpMethod httpMethod)
      Sets the HTTP method and returns the current request
      Specified by:
      withHttpMethod in interface IHttpRequest
      Parameters:
      httpMethod - the HTTP method
      Returns:
      the current request
    • getClient

      @Nonnull public IBaseClient<?> getClient()
      Gets the client
      Returns:
      the client
    • getResponseType

      @Nullable public Class<? extends T> getResponseType()
      Gets the response type
      Returns:
      the response type
    • setMaxRedirects

      public void setMaxRedirects(int maxRedirects)
      Sets the max redirects
      Specified by:
      setMaxRedirects in interface IHttpRequest
      Parameters:
      maxRedirects - Max redirects that a request can take
    • getMaxRedirects

      public int getMaxRedirects()
      Gets the max redirects
      Specified by:
      getMaxRedirects in interface IHttpRequest
      Returns:
      Max redirects that a request can take
    • setShouldRedirect

      public void setShouldRedirect(@Nonnull IShouldRedirect shouldRedirect)
      Sets the should redirect callback
      Specified by:
      setShouldRedirect in interface IHttpRequest
      Parameters:
      shouldRedirect - Callback called before doing a redirect
    • getShouldRedirect

      @Nonnull public IShouldRedirect getShouldRedirect()
      Gets the should redirect callback
      Specified by:
      getShouldRedirect in interface IHttpRequest
      Returns:
      Callback which is called before redirect
    • setShouldRetry

      public void setShouldRetry(@Nonnull IShouldRetry shouldretry)
      Sets the should retry callback
      Specified by:
      setShouldRetry in interface IHttpRequest
      Parameters:
      shouldretry - The callback called before retry
    • getShouldRetry

      @Nonnull public IShouldRetry getShouldRetry()
      Gets the should retry callback
      Specified by:
      getShouldRetry in interface IHttpRequest
      Returns:
      Callback called before retry
    • setMaxRetries

      public void setMaxRetries(int maxRetries)
      Sets the max retries
      Specified by:
      setMaxRetries in interface IHttpRequest
      Parameters:
      maxRetries - Max retries for a request
    • getMaxRetries

      public int getMaxRetries()
      Gets max retries
      Specified by:
      getMaxRetries in interface IHttpRequest
      Returns:
      Max retries for a request
    • setDelay

      public void setDelay(long delay)
      Sets the delay in seconds between retires
      Specified by:
      setDelay in interface IHttpRequest
      Parameters:
      delay - Delay in seconds between retries
    • getDelay

      public long getDelay()
      Gets delay between retries
      Specified by:
      getDelay in interface IHttpRequest
      Returns:
      Delay between retries in seconds