Package com.shaft.api

Class RequestBuilder

java.lang.Object
com.shaft.api.RequestBuilder

public class RequestBuilder extends Object
  • Method Details

    • useRelaxedHTTPSValidation

      public RequestBuilder useRelaxedHTTPSValidation()
      set useRelaxedHTTPSValidation configuration to trust all hosts regardless if the SSL certificate is invalid in the request builder 'SSL' is the protocol name by default
      Returns:
      a self-reference to be used to continue building your API request
    • useRelaxedHTTPSValidation

      public RequestBuilder useRelaxedHTTPSValidation(String protocol)
      set useRelaxedHTTPSValidation configuration to trust all hosts regardless if the SSL certificate is invalid in the request builder *
      Parameters:
      protocol - The standard name of the requested protocol.
      Returns:
      a self-reference to be used to continue building your API request
    • setTargetStatusCode

      public RequestBuilder setTargetStatusCode(int targetStatusCode)
      Sets the expected target status code for the API request that you're currently building. By default, this value is set to any number between 200 and 299 which means that the request was successful as per the W3C Standard documentation.
      Parameters:
      targetStatusCode - the expected target status code.
      Returns:
      a self-reference to be used to continue building your API request
    • setUrlArguments

      public RequestBuilder setUrlArguments(String urlArguments)
      Sets the url arguments (if any) for the API request that you're currently building. A request usually has only one of the following: urlArguments, parameters+type, or body
      Parameters:
      urlArguments - '&' separated arguments without a preceding '?', is nullable, Example: "username=test&password=test"
      Returns:
      a self-reference to be used to continue building your API request
    • setParameters

      public RequestBuilder setParameters(List<List<Object>> parameters, RestActions.ParametersType parametersType)
      Sets the parameters (if any) for the API request that you're currently building. A request usually has only one of the following: urlArguments, parameters+type, or body
      Parameters:
      parameters - a list of key/value pairs that will be sent as parameters with this API call, is nullable, Example: Arrays.asList(Arrays.asList("itemId", "123"), Arrays.asList("contents", XMLContents));
      parametersType - FORM, QUERY
      Returns:
      a self-reference to be used to continue building your API request
    • setRequestBody

      public RequestBuilder setRequestBody(Object requestBody)
      Sets the body (if any) for the API request that you're currently building. A request usually has only one of the following: urlArguments, parameters+type, or body
      Parameters:
      requestBody - Specify an Object request content that will automatically be serialized to JSON or XML and sent with the request. If the object is a primitive or Number the object will be converted to a String and put in the request body. This works for the POST, PUT and PATCH methods only. Trying to do this for the other http methods will cause an exception to be thrown.
      Returns:
      a self-reference to be used to continue building your API request
    • setRequestBodyFromFile

      public RequestBuilder setRequestBodyFromFile(String relativeFilePath)
      Sets the body (if any) for the API request that you're currently building. A request usually has only one of the following: urlArguments, parameters+type, or body
      Parameters:
      relativeFilePath - Specify the path to a file that will be used as an Object request content that will automatically be serialized to JSON or XML and sent with the request. If the object is a primitive or Number the object will be converted to a String and put in the request body. This works for the POST, PUT and PATCH methods only. Trying to do this for the other http methods will cause an exception to be thrown.
      Returns:
      a self-reference to be used to continue building your API request
    • setContentType

      public RequestBuilder setContentType(io.restassured.http.ContentType contentType)
      Sets the content type for the API request that you're currently building. By default, this value is set to `ContentType.ANY` but you can change it by calling this method.
      Parameters:
      contentType - Enumeration of common IANA content-types. This may be used to specify a request or response content-type more easily than specifying the full string each time. Example: ContentType.ANY
      Returns:
      a self-reference to be used to continue building your API request
    • setContentType

      public RequestBuilder setContentType(String contentType)
      Sets the content type for the API request that you're currently building. By default, this value is set to `ContentType.ANY` but you can change it by calling this method.
      Parameters:
      contentType - String value representing IANA content-type.
      Returns:
      a self-reference to be used to continue building your API request
    • appendDefaultContentCharsetToContentTypeIfUndefined

      public RequestBuilder appendDefaultContentCharsetToContentTypeIfUndefined(boolean appendDefaultContentCharsetToContentTypeIfUndefined)
      Tells whether REST Assured should automatically append the content charset to the content-type header if not defined explicitly. Note that this does not affect multipart form data. Default is true.
      Parameters:
      appendDefaultContentCharsetToContentTypeIfUndefined - Whether REST Assured should automatically append the content charset to the content-type header if not defined explicitly.
      Returns:
      a self-reference to be used to continue building your API request
    • enableUrlEncoding

      public RequestBuilder enableUrlEncoding(boolean urlEncodingEnabled)
      Tells whether REST Assured should automatically encode the URI if not defined explicitly. Note that this does not affect multipart form data. Default is true.
      Parameters:
      urlEncodingEnabled - Whether REST Assured should automatically encode the URI if not defined explicitly.
      Returns:
      a self-reference to be used to continue building your API request
    • addHeader

      public RequestBuilder addHeader(String key, String value)
      Append a header to the current session to be used in the current and all the following requests. This feature is commonly used for authentication tokens.
      Parameters:
      key - the name of the header that you want to add
      value - the value that will be put inside the key
      Returns:
      a self-reference to be used to continue building your API request
    • addCookie

      public RequestBuilder addCookie(String key, Object value)
      Append a cookie to the current session to be used in the current and all the following requests. This feature is commonly used for authentication cookies.
      Parameters:
      key - the name of the cookie that you want to add
      value - the value that will be put inside the key
      Returns:
      a self-reference to be used to continue building your API request
    • setAuthentication

      public RequestBuilder setAuthentication(String username, String password, RequestBuilder.AuthenticationType authenticationType)
      Set the authentication method that will be used by the API request that you're currently building. By default, this value is set to `AuthenticationType.NONE` but you can change it by calling this method. If you use this method the authentication token will be saved automatically for all the following requests using the same session.
      Parameters:
      username - the value of the username that you will be using to authenticate the current API request.
      password - the value of the password that you will be using to authenticate the current API request.
      authenticationType - the type of your authentication method {BASIC, FORM, NONE}
      Returns:
      a self-reference to be used to continue building your API request
    • perform

      public io.restassured.response.Response perform()
      After you finish building your request, use this method to trigger the request and get back the response object.
      Returns:
      Response; returns the full response object for further manipulation
    • performRequest

      @Step("Perform {this.requestType} request to {this.serviceURI}{this.serviceName}") public io.restassured.response.Response performRequest()
      After you finish building your request, use this method to trigger the request and get back the response object.
      Returns:
      Response; returns the full response object for further manipulation