Java DSL for easy testing of REST services
—
Comprehensive configuration capabilities for HTTP client behavior, SSL/TLS settings, logging, global defaults, proxy settings, and object mapping customization for REST Assured testing.
Static fields for configuring global defaults that apply to all requests.
// Global URI and path configuration
static String baseURI; // Default: "http://localhost"
static int port; // Default: 8080 (use UNDEFINED_PORT for default)
static String basePath; // Default: "" (empty string)
// Global authentication and specifications
static AuthenticationScheme authentication; // Default: no authentication
static RequestSpecification requestSpecification; // Default: null
static ResponseSpecification responseSpecification; // Default: null
// Global behavior configuration
static boolean urlEncodingEnabled; // Default: true
static String rootPath; // Default: "" (empty string)
static String sessionId; // Default: null
static Parser defaultParser; // Default: null
static ProxySpecification proxy; // Default: null
// Global configuration object
static RestAssuredConfig config; // Default: new RestAssuredConfig()Usage Examples:
// Set global base configuration
RestAssured.baseURI = "https://api.example.com";
RestAssured.port = 443;
RestAssured.basePath = "/v1";
// Global authentication
RestAssured.authentication = basic("user", "password");
// Global request specification
RestAssured.requestSpecification = new RequestSpecBuilder()
.addHeader("Accept", "application/json")
.addQueryParam("api_key", "123456")
.build();
// URL encoding configuration
RestAssured.urlEncodingEnabled = false; // Disable for pre-encoded URLs
// Default parser for responses without content-type
RestAssured.defaultParser = Parser.JSON;Static methods for configuring global behavior and resetting configuration.
/**
* Reset all global configuration to default values
*/
static void reset();
/**
* Register a custom parser for specific content types
* @param contentType The content type to register parser for
* @param parser The parser to use for this content type
*/
static void registerParser(String contentType, Parser parser);
/**
* Unregister a custom parser for a content type
* @param contentType The content type to unregister parser for
*/
static void unregisterParser(String contentType);
/**
* Enable logging of requests and responses when validation fails
*/
static void enableLoggingOfRequestAndResponseIfValidationFails();
/**
* Enable logging of requests and responses when validation fails with specific detail level
* @param logDetail The level of detail to log
*/
static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail);Usage Examples:
// Register custom parser for specific content type
RestAssured.registerParser("application/vnd.api+json", Parser.JSON);
// Enable failure logging
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL);
// Reset all configuration to defaults
RestAssured.reset();Methods for configuring SSL/TLS behavior, certificates, and trust stores.
/**
* Use relaxed HTTPS validation (trust all certificates)
*/
static void useRelaxedHTTPSValidation();
/**
* Use relaxed HTTPS validation with specific SSL protocol
* @param protocol The SSL protocol to use (e.g., "TLS", "SSL")
*/
static void useRelaxedHTTPSValidation(String protocol);
/**
* Configure keystore for client certificate authentication
* @param pathToJks Path to JKS keystore file
* @param password Keystore password
*/
static void keyStore(String pathToJks, String password);
/**
* Configure keystore from File object
* @param pathToJks File object pointing to JKS keystore
* @param password Keystore password
*/
static void keyStore(File pathToJks, String password);
/**
* Configure keystore using default user keystore
* @param password Keystore password (use null for no password)
*/
static void keyStore(String password);
/**
* Configure truststore for server certificate validation
* @param pathToJks Path to JKS truststore file
* @param password Truststore password
*/
static void trustStore(String pathToJks, String password);
/**
* Configure truststore from File object
* @param pathToJks File object pointing to JKS truststore
* @param password Truststore password
*/
static void trustStore(File pathToJks, String password);
/**
* Configure truststore from KeyStore object
* @param truststore Pre-loaded KeyStore object
*/
static void trustStore(KeyStore truststore);Usage Examples:
// Relaxed HTTPS validation (development/testing only)
RestAssured.useRelaxedHTTPSValidation();
// Client certificate authentication
RestAssured.keyStore("/path/to/client-keystore.jks", "keystorePassword");
// Custom truststore for server validation
RestAssured.trustStore("/path/to/custom-truststore.jks", "truststorePassword");
// Using KeyStore object
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream("truststore.jks"), "password".toCharArray());
RestAssured.trustStore(trustStore);Methods for configuring HTTP proxy settings.
/**
* Configure proxy with host and port
* @param host Proxy hostname
* @param port Proxy port
*/
static void proxy(String host, int port);
/**
* Configure proxy with host only (default port 8888)
* @param host Proxy hostname or URI string
*/
static void proxy(String host);
/**
* Configure proxy with localhost and specific port
* @param port Proxy port
*/
static void proxy(int port);
/**
* Configure proxy with host, port, and scheme
* @param host Proxy hostname
* @param port Proxy port
* @param scheme HTTP scheme (http or https)
*/
static void proxy(String host, int port, String scheme);
/**
* Configure proxy using URI
* @param uri Proxy URI
*/
static void proxy(URI uri);
/**
* Configure proxy using ProxySpecification
* @param proxySpecification Detailed proxy configuration
*/
static void proxy(ProxySpecification proxySpecification);Usage Examples:
// Basic proxy configuration
RestAssured.proxy("proxy.company.com", 8080);
// Proxy with authentication (using ProxySpecification)
RestAssured.proxy = ProxySpecification.host("proxy.company.com")
.withPort(8080)
.withAuth("proxyUser", "proxyPassword");
// HTTPS proxy
RestAssured.proxy("proxy.company.com", 8080, "https");Methods for configuring global filters that apply to all requests.
/**
* Add filters to be applied to all requests
* @param filters List of filters to add
*/
static void filters(List<Filter> filters);
/**
* Add filters to be applied to all requests
* @param filter First filter to add
* @param additionalFilters Additional filters to add
*/
static void filters(Filter filter, Filter... additionalFilters);
/**
* Replace all existing filters with new filters
* @param filters List of filters to set
*/
static void replaceFiltersWith(List<Filter> filters);
/**
* Replace all existing filters with new filters
* @param filter First filter to set
* @param additionalFilters Additional filters to set
*/
static void replaceFiltersWith(Filter filter, Filter... additionalFilters);
/**
* Get current list of global filters
* @return Unmodifiable list of current filters
*/
static List<Filter> filters();Usage Examples:
// Add global logging filters
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
// Add timing filter
RestAssured.filters(new TimingFilter());
// Replace existing filters
RestAssured.replaceFiltersWith(new ErrorLoggingFilter());Main configuration object that aggregates all configuration options.
/**
* Get current configuration or create new default configuration
* @return Current RestAssuredConfig instance
*/
static RestAssuredConfig config();
class RestAssuredConfig {
/**
* Get SSL configuration
* @return SSL configuration object
*/
SSLConfig getSSLConfig();
/**
* Configure SSL settings
* @param sslConfig SSL configuration
* @return Updated configuration
*/
RestAssuredConfig sslConfig(SSLConfig sslConfig);
/**
* Get HTTP client configuration
* @return HTTP client configuration object
*/
HttpClientConfig getHttpClientConfig();
/**
* Configure HTTP client settings
* @param httpClientConfig HTTP client configuration
* @return Updated configuration
*/
RestAssuredConfig httpClient(HttpClientConfig httpClientConfig);
/**
* Get logging configuration
* @return Logging configuration object
*/
LogConfig getLogConfig();
/**
* Configure logging settings
* @param logConfig Logging configuration
* @return Updated configuration
*/
RestAssuredConfig logConfig(LogConfig logConfig);
/**
* Get object mapper configuration
* @return Object mapper configuration object
*/
ObjectMapperConfig getObjectMapperConfig();
/**
* Configure object mapping settings
* @param objectMapperConfig Object mapper configuration
* @return Updated configuration
*/
RestAssuredConfig objectMapperConfig(ObjectMapperConfig objectMapperConfig);
/**
* Get JSON configuration
* @return JSON configuration object
*/
JsonConfig getJsonConfig();
/**
* Configure JSON processing settings
* @param jsonConfig JSON configuration
* @return Updated configuration
*/
RestAssuredConfig jsonConfig(JsonConfig jsonConfig);
/**
* Get XML configuration
* @return XML configuration object
*/
XmlConfig getXmlConfig();
/**
* Configure XML processing settings
* @param xmlConfig XML configuration
* @return Updated configuration
*/
RestAssuredConfig xmlConfig(XmlConfig xmlConfig);
}Detailed SSL/TLS configuration options.
class SSLConfig {
/**
* Create default SSL configuration
* @return Default SSL configuration
*/
static SSLConfig sslConfig();
/**
* Enable relaxed HTTPS validation
* @return Updated SSL configuration
*/
SSLConfig relaxedHTTPSValidation();
/**
* Enable relaxed HTTPS validation with specific protocol
* @param protocol SSL protocol to use
* @return Updated SSL configuration
*/
SSLConfig relaxedHTTPSValidation(String protocol);
/**
* Configure keystore
* @param pathToJks Path to keystore file
* @param password Keystore password
* @return Updated SSL configuration
*/
SSLConfig keyStore(String pathToJks, String password);
/**
* Configure keystore from File
* @param pathToJks File pointing to keystore
* @param password Keystore password
* @return Updated SSL configuration
*/
SSLConfig keyStore(File pathToJks, String password);
/**
* Configure keystore from KeyStore object
* @param keyStore Pre-loaded KeyStore
* @return Updated SSL configuration
*/
SSLConfig keyStore(KeyStore keyStore);
/**
* Configure truststore
* @param pathToJks Path to truststore file
* @param password Truststore password
* @return Updated SSL configuration
*/
SSLConfig trustStore(String pathToJks, String password);
/**
* Configure truststore from KeyStore object
* @param trustStore Pre-loaded truststore
* @return Updated SSL configuration
*/
SSLConfig trustStore(KeyStore trustStore);
/**
* Allow all hostnames (disable hostname verification)
* @return Updated SSL configuration
*/
SSLConfig allowAllHostnames();
}Configuration for the underlying HTTP client behavior.
class HttpClientConfig {
/**
* Create default HTTP client configuration
* @return Default HTTP client configuration
*/
static HttpClientConfig httpClientConfig();
/**
* Set connection timeout
* @param timeoutInMs Timeout in milliseconds
* @return Updated HTTP client configuration
*/
HttpClientConfig setParam(String parameterName, Object parameterValue);
/**
* Configure HTTP client parameters
* @param httpClientParams Map of HTTP client parameters
* @return Updated HTTP client configuration
*/
HttpClientConfig httpClientParams(Map<String, Object> httpClientParams);
/**
* Configure custom HTTP client factory
* @param httpClientFactory Custom HTTP client factory
* @return Updated HTTP client configuration
*/
HttpClientConfig httpClientFactory(HttpClientFactory httpClientFactory);
}Configuration for request and response logging behavior.
class LogConfig {
/**
* Create default logging configuration
* @return Default logging configuration
*/
static LogConfig logConfig();
/**
* Enable logging of requests and responses on validation failure
* @return Updated logging configuration
*/
LogConfig enableLoggingOfRequestAndResponseIfValidationFails();
/**
* Enable logging of requests and responses on validation failure with detail level
* @param logDetail Level of detail to log
* @return Updated logging configuration
*/
LogConfig enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail);
/**
* Enable pretty printing of request and response bodies
* @param shouldPrettyPrint Whether to enable pretty printing
* @return Updated logging configuration
*/
LogConfig enablePrettyPrinting(boolean shouldPrettyPrint);
/**
* Configure default stream for logging output
* @param defaultStream Stream to write log output to
* @return Updated logging configuration
*/
LogConfig defaultStream(PrintStream defaultStream);
}Configuration for JSON/XML serialization and deserialization.
class ObjectMapperConfig {
/**
* Create default object mapper configuration
* @return Default object mapper configuration
*/
static ObjectMapperConfig objectMapperConfig();
/**
* Configure default object mapper type
* @param defaultObjectMapperType Default mapper type to use
* @return Updated object mapper configuration
*/
ObjectMapperConfig defaultObjectMapperType(ObjectMapperType defaultObjectMapperType);
/**
* Configure custom object mapper for serialization
* @param objectMapper Custom object mapper
* @return Updated object mapper configuration
*/
ObjectMapperConfig defaultObjectMapper(ObjectMapper objectMapper);
/**
* Configure Jackson 1.x object mapper
* @param objectMapper Jackson 1.x ObjectMapper instance
* @return Updated object mapper configuration
*/
ObjectMapperConfig jackson1ObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper);
/**
* Configure Jackson 2.x object mapper
* @param objectMapper Jackson 2.x ObjectMapper instance
* @return Updated object mapper configuration
*/
ObjectMapperConfig jackson2ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper);
/**
* Configure Gson object mapper
* @param gson Gson instance
* @return Updated object mapper configuration
*/
ObjectMapperConfig gsonObjectMapper(Gson gson);
/**
* Configure JAXB context path
* @param contextPath JAXB context path
* @return Updated object mapper configuration
*/
ObjectMapperConfig jaxbObjectMapper(String contextPath);
}// Main configuration class
class RestAssuredConfig {
// All configuration methods listed above
}
// Parser enumeration for response content parsing
enum Parser {
JSON, XML, HTML, TEXT
}
// Log detail levels for logging configuration
enum LogDetail {
ALL, STATUS, HEADERS, COOKIES, BODY, PARAMS, METHOD, URI
}
// Object mapper types
enum ObjectMapperType {
JACKSON_1, JACKSON_2, GSON, JAXB
}
// Proxy specification
class ProxySpecification {
static ProxySpecification host(String host);
ProxySpecification withPort(int port);
ProxySpecification withAuth(String username, String password);
ProxySpecification withScheme(String scheme);
}
// Constants for configuration
interface RestAssured {
String DEFAULT_URI = "http://localhost";
int DEFAULT_PORT = 8080;
int UNDEFINED_PORT = -1;
String DEFAULT_PATH = "";
String DEFAULT_BODY_ROOT_PATH = "";
boolean DEFAULT_URL_ENCODING_ENABLED = true;
String DEFAULT_SESSION_ID_VALUE = null;
}Usage Examples:
// Complete configuration example
RestAssuredConfig config = RestAssuredConfig.config()
.sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation())
.httpClient(HttpClientConfig.httpClientConfig()
.setParam("http.connection.timeout", 5000)
.setParam("http.socket.timeout", 10000))
.logConfig(LogConfig.logConfig()
.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)
.enablePrettyPrinting(true))
.objectMapperConfig(ObjectMapperConfig.objectMapperConfig()
.defaultObjectMapperType(ObjectMapperType.JACKSON_2))
.jsonConfig(JsonConfig.jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL));
// Apply configuration globally
RestAssured.config = config;
// Or apply to specific request
given()
.config(config)
.when()
.get("/api/data");Install with Tessl CLI
npx tessl i tessl/maven-io-rest-assured--rest-assured