Class SHAFT.API
java.lang.Object
com.shaft.driver.SHAFT.API
- Enclosing class:
SHAFT
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 Summary
ConstructorsConstructorDescriptionAPI(RestActions existingSession) Wraps an existingRestActionssession for continued use.Creates a new API session pointing at the given base service URI. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a persistent cookie that will be sent with every subsequent request in this session.voidAdds a persistent header that will be sent with every subsequent request in this session.Starts building a hard assertion against the last API response.Builds a DELETE request for the specified service endpoint.Builds a GET request for the specified service endpoint.static SHAFT.APIgetInstance(String serviceURI) Factory method equivalent tonew API(serviceURI).io.restassured.response.ResponseReturns the raw REST AssuredResponsefrom the most recent request.Returns the response body of the most recent request as a string.getResponseJSONValue(String jsonPath) Extracts a value from the most recent JSON response using a JSONPath expression.getResponseJSONValueAsList(String jsonPath) Extracts a list of values from the most recent JSON response using a JSONPath expression.intReturns the HTTP status code of the most recent response.longReturns the response time in milliseconds for the most recent request.getResponseXMLValue(String xmlPath) Extracts a value from the most recent XML response using an XPath expression.getResponseXMLValueAsList(String xmlPath) Extracts a list of values from the most recent XML response using an XPath expression.Builds a PATCH request for the specified service endpoint.Builds a POST request for the specified service endpoint.Builds a PUT request for the specified service endpoint.Starts building a soft verification against the last API response.
-
Constructor Details
-
API
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
Wraps an existingRestActionssession for continued use.- Parameters:
existingSession- an already-initialised REST session
-
-
Method Details
-
getInstance
-
get
Builds a GET request for the specified service endpoint.- Parameters:
serviceName- the endpoint path (appended to the base URI)- Returns:
- a
RequestBuilderfor further request configuration
-
post
Builds a POST request for the specified service endpoint.- Parameters:
serviceName- the endpoint path (appended to the base URI)- Returns:
- a
RequestBuilderfor further request configuration
-
patch
Builds a PATCH request for the specified service endpoint.- Parameters:
serviceName- the endpoint path (appended to the base URI)- Returns:
- a
RequestBuilderfor further request configuration
-
delete
Builds a DELETE request for the specified service endpoint.- Parameters:
serviceName- the endpoint path (appended to the base URI)- Returns:
- a
RequestBuilderfor further request configuration
-
put
Builds a PUT request for the specified service endpoint.- Parameters:
serviceName- the endpoint path (appended to the base URI)- Returns:
- a
RequestBuilderfor further request configuration
-
addHeader
-
addCookie
-
assertThatResponse
Starts building a hard assertion against the last API response.- Returns:
- a
RestValidationsBuilderfor response assertions
-
verifyThatResponse
Starts building a soft verification against the last API response.- Returns:
- a
RestValidationsBuilderfor response verifications
-
getResponse
public io.restassured.response.Response getResponse()Returns the raw REST AssuredResponsefrom the most recent request.- Returns:
- the last
Response
-
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
-
getResponseJSONValueAsList
-
getResponseXMLValue
-
getResponseXMLValueAsList
-