Interface HttpRequest


public interface HttpRequest
Represents an HTTP request.
  • Method Details

    • setMethod

      HttpRequest setMethod(HttpMethod method)
      Specifies the HTTP method of the request. If not specified, requests with a setBody method default to POST and all other requests default to GET.
      Parameters:
      method - HTTP method
      Returns:
      this HTTP request
    • setHeader

      HttpRequest setHeader(String name, String value)
      Specifies an HTTP request header. Each call with the same name adds to the List of already specified values. Use only the following request headers with setHeader:
      Parameters:
      name - header name. Cannot be null or empty.
      value - header value. Cannot be null.
      Returns:
      this HTTP request
    • appendPath

      HttpRequest appendPath(String path)
      Appends the given path to the base URL.
      Parameters:
      path - path to append. Cannot be null.
      Returns:
      this HTTP request
    • setQuerystringParam

      HttpRequest setQuerystringParam(String name, String value)
      Specifies a query string param.
      Parameters:
      name - query string param name. Cannot be null or empty.
      value - query string param value. Cannot be null.
      Returns:
      this HTTP request
    • setBodyParam

      HttpRequest setBodyParam(String name, String value)
      Specifies a body param. Header defaults to Content-Type: application/x-www-form-urlencoded; charset=utf-8. If header is set to Content-Type: text/plain; charset=utf-8, body param name-value pairs will be encoded. Otherwise, if body encoding is not expected, use setBody(String).
      Parameters:
      name - body param name. Cannot be null or empty.
      value - body param value. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      HttpRequest setBody(String body)
      Specifies request body as a string. Header defaults to Content-Type: application/x-www-form-urlencoded; charset=utf-8.
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      HttpRequest setBody(CsvData body)
      Specifies request body as CSV as returned by CsvData.asString(). Header defaults to Content-Type: text/csv; charset=utf-8.
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      HttpRequest setBody(JsonObject body)
      Specifies request body as JSON as returned by JsonObject.asString(). Header defaults to Content-Type: application/json; charset=utf-8.
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      HttpRequest setBody(JsonArray body)
      Specifies request body as JSON as returned by JsonArray.asString(). Header defaults to Content-Type: application/json; charset=utf-8.
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      <U extends UserDefinedModel> HttpRequest setBody(U body)
      Specifies request body as the serialized form of the provided UserDefinedModel. To specify a specific content type to serialize the body to, set the Content-Type header (see setContentType(HttpRequestContentType)).

      Note: This method will fail if the Content-Type header has been set to a value that is not supported by UserDefinedModel.

      Header defaults to Content-Type: application/json; charset=utf-8.
      Type Parameters:
      U - type of UserDefinedModel
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setBody

      <U extends UserDefinedModel> HttpRequest setBody(Collection<U> body)
      Specifies request body as the serialized form of the provided UserDefinedModels. To specify a specific content type to serialize the body to, set the Content-Type header (see setContentType(HttpRequestContentType)).

      Note: This method will fail if the Content-Type header has been set to a value that is not supported by UserDefinedModel.

      Header defaults to Content-Type: application/json; charset=utf-8.
      Type Parameters:
      U - type of UserDefinedModel
      Parameters:
      body - request body. Cannot be null.
      Returns:
      this HTTP request
    • setTimeout

      HttpRequest setTimeout(int timeout)
      Specifies the maximum time in milliseconds to wait for this HTTP request to complete execution. Must be greater than 0.
      Parameters:
      timeout - timeout in milliseconds
      Returns:
      this HTTP request
    • setTokenRequest

      HttpRequest setTokenRequest(TokenRequest tokenRequest)
      Specifies the custom tokens that should be resolved in headers, body parameters, and body.

      For these tokens to be resolved, token resolution must be enabled with setResolveTokens(boolean).

      Parameters:
      tokenRequest - the token request containing the mapping from token names to their values. Cannot be null.
      Returns:
      this HTTP request
    • setResolveTokens

      HttpRequest setResolveTokens(boolean resolveTokens)
      Specifies whether to resolve tokens used in headers, body parameters, and body. Tokens used in query string parameters are not resolved.

      By default, tokens are not resolved. You must call this method to resolve tokens.

      Parameters:
      resolveTokens - true if tokens have to be resolved, otherwise false
      Returns:
      this HTTP request
    • setContentType

      HttpRequest setContentType(com.veeva.vault.sdk.infrastructure.http.HttpRequestContentEnumType contentType)
      Specifies the Content-Type header for this HTTP request. Calling this method is effectively the same as calling setHeader(String, String) and passing in "Content-Type" as the header, for example:

      setHeader("Content-Type","application/json")

      Parameters:
      contentType - the content type to serialize this request's body as. Cannot be null.
      Returns:
      this HTTP request
    • setContentType

      HttpRequest setContentType(HttpRequestContentType contentType)
      Specifies the Content-Type header for this HTTP request. Calling this method is effectively the same as calling setHeader(String, String) and passing in "Content-Type" as the header, for example:

      setHeader("Content-Type","application/json")

      Parameters:
      contentType - the content type to serialize this request's body as. Cannot be null.
      Returns:
      this HTTP request