Class SHAFT.API

java.lang.Object
com.shaft.driver.SHAFT.API
Enclosing class:
SHAFT

public static class SHAFT.API extends Object
Manages a REST API session and exposes a fluent interface for building and executing HTTP requests (GET, POST, PUT, PATCH, DELETE).

Usage example:

SHAFT.API api = new SHAFT.API("https://jsonplaceholder.typicode.com");
api.get("/posts/1").setTargetStatusCode(200).performRequest();
api.assertThatResponse().extractedJsonValue("$.title").isNotNull().perform();
See Also:
  • Constructor Details

    • API

      public API(String serviceURI)
      Creates a new API session pointing at the given base service URI.
      Parameters:
      serviceURI - the base URI of the target web service (e.g., "https://api.example.com")
    • API

      public API(RestActions existingSession)
      Wraps an existing RestActions session for continued use.
      Parameters:
      existingSession - an already-initialised REST session
  • Method Details

    • getInstance

      public static SHAFT.API getInstance(String serviceURI)
      Factory method equivalent to new API(serviceURI).
      Parameters:
      serviceURI - the base URI of the target web service
      Returns:
      a new SHAFT.API instance
    • get

      public RequestBuilder get(String serviceName)
      Builds a GET request for the specified service endpoint.
      Parameters:
      serviceName - the endpoint path (appended to the base URI)
      Returns:
      a RequestBuilder for further request configuration
    • post

      public RequestBuilder post(String serviceName)
      Builds a POST request for the specified service endpoint.
      Parameters:
      serviceName - the endpoint path (appended to the base URI)
      Returns:
      a RequestBuilder for further request configuration
    • patch

      public RequestBuilder patch(String serviceName)
      Builds a PATCH request for the specified service endpoint.
      Parameters:
      serviceName - the endpoint path (appended to the base URI)
      Returns:
      a RequestBuilder for further request configuration
    • delete

      public RequestBuilder delete(String serviceName)
      Builds a DELETE request for the specified service endpoint.
      Parameters:
      serviceName - the endpoint path (appended to the base URI)
      Returns:
      a RequestBuilder for further request configuration
    • put

      public RequestBuilder put(String serviceName)
      Builds a PUT request for the specified service endpoint.
      Parameters:
      serviceName - the endpoint path (appended to the base URI)
      Returns:
      a RequestBuilder for further request configuration
    • addHeader

      public void addHeader(String key, String value)
      Adds a persistent header that will be sent with every subsequent request in this session.
      Parameters:
      key - the header name
      value - the header value
    • addCookie

      public void addCookie(String key, String value)
      Adds a persistent cookie that will be sent with every subsequent request in this session.
      Parameters:
      key - the cookie name
      value - the cookie value
    • assertThatResponse

      public RestValidationsBuilder assertThatResponse()
      Starts building a hard assertion against the last API response.
      Returns:
      a RestValidationsBuilder for response assertions
    • verifyThatResponse

      public RestValidationsBuilder verifyThatResponse()
      Starts building a soft verification against the last API response.
      Returns:
      a RestValidationsBuilder for response verifications
    • getResponse

      public io.restassured.response.Response getResponse()
      Returns the raw REST Assured Response from the most recent request.
      Returns:
      the last Response
    • getResponseBody

      public String getResponseBody()
      Returns the response body of the most recent request as a string.
      Returns:
      the response body text
    • getResponseStatusCode

      public int getResponseStatusCode()
      Returns the HTTP status code of the most recent response.
      Returns:
      the status code (e.g., 200, 404)
    • getResponseTime

      public long getResponseTime()
      Returns the response time in milliseconds for the most recent request.
      Returns:
      the response time in milliseconds
    • getResponseJSONValue

      public String getResponseJSONValue(String jsonPath)
      Extracts a value from the most recent JSON response using a JSONPath expression.
      Parameters:
      jsonPath - the JSONPath expression (e.g., "$.data.id")
      Returns:
      the extracted value as a string
    • getResponseJSONValueAsList

      public List<Object> getResponseJSONValueAsList(String jsonPath)
      Extracts a list of values from the most recent JSON response using a JSONPath expression.
      Parameters:
      jsonPath - the JSONPath expression
      Returns:
      the extracted values as a list of objects
    • getResponseXMLValue

      public String getResponseXMLValue(String xmlPath)
      Extracts a value from the most recent XML response using an XPath expression.
      Parameters:
      xmlPath - the XPath expression
      Returns:
      the extracted value as a string
    • getResponseXMLValueAsList

      public List<Object> getResponseXMLValueAsList(String xmlPath)
      Extracts a list of values from the most recent XML response using an XPath expression.
      Parameters:
      xmlPath - the XPath expression
      Returns:
      the extracted values as a list of objects