RequestSpecification

open class RequestSpecification<P : Any>(val method: Matcher<HttpMethod>? = null, val path: Matcher<String>? = null, val headers: List<Matcher<Headers>> = listOf(), val body: List<Matcher<P?>> = listOf(), val bodyString: List<Matcher<String?>> = listOf(), val priority: Int = DEFAULT_STUB_PRIORITY, requestType: KClass<P>)(source)

Represents a specification for matching incoming HTTP requests based on defined criteria, such as HTTP method, request path, and request body.

This class is used to define the criteria against which incoming requests are tested. It provides functionality for checking whether a given request satisfies the specified conditions and supports prioritization for defining matching order.

Type Parameters

P

type of the request payload

Constructors

Link copied to clipboard
constructor(method: Matcher<HttpMethod>? = null, path: Matcher<String>? = null, headers: List<Matcher<Headers>> = listOf(), body: List<Matcher<P?>> = listOf(), bodyString: List<Matcher<String?>> = listOf(), priority: Int = DEFAULT_STUB_PRIORITY, requestType: KClass<P>)

Properties

Link copied to clipboard
val body: List<Matcher<P?>>

List of matchers for the request body as a P. All matchers must pass for a match to succeed.

Link copied to clipboard
val bodyString: List<Matcher<String?>>

List of matchers for the request body as a String. All matchers must pass for a match to succeed. Note: when both body and bodyString matchers are active, the request body is read twice. The Ktor DoubleReceive plugin must be installed on the server for this to work correctly; without it the second receive() call will fail silently and all matchers in the later group will be treated as not matched.

Link copied to clipboard
val headers: List<Matcher<Headers>>

List of matchers for Ktor Headers object. All matchers must pass for a match to succeed.

Link copied to clipboard
val method: Matcher<HttpMethod>?

Matcher for the HTTP method of the request. If null, the method is not validated.

Link copied to clipboard
val path: Matcher<String>?

Matcher for the request path. If null, the path is not validated.

Link copied to clipboard

The priority value used for comparing different specifications. Higher values indicate higher priority. Default value is DEFAULT_STUB_PRIORITY (0). Negative values can be used for catch-all / fallback stubs.