ResponseDefinitionBuilder

open class ResponseDefinitionBuilder<P : Any, T : Any>(val request: CapturedRequest<P>, var contentType: ContentType? = null, var body: T? = null, httpStatusCode: Int = 200, httpStatus: HttpStatusCode = HttpStatusCode.fromValue(httpStatusCode), formatter: HttpFormatter) : AbstractResponseDefinitionBuilder<P, T> (source)

Builder for constructing a definition of an HTTP response with configurable attributes.

Parameters

P

The type of the request body.

T

The type of the response body.

headers

A mutable list of additional custom headers for the response.

Inherits functionality from AbstractResponseDefinitionBuilder to allow additional header manipulations and provides a concrete implementation of the response building process.

Constructors

Link copied to clipboard
constructor(request: CapturedRequest<P>, contentType: ContentType? = null, body: T? = null, httpStatusCode: Int = 200, httpStatus: HttpStatusCode = HttpStatusCode.fromValue(httpStatusCode), formatter: HttpFormatter)

Properties

Link copied to clipboard
var body: T?

The body of the response. Can be null.

Link copied to clipboard

Optional MIME type of the response. Defaults to null if not specified.

Link copied to clipboard
Link copied to clipboard

Entry point for header configuration. Supports two syntaxes:

Link copied to clipboard

The HTTP status code to be associated with the response.

Link copied to clipboard
Link copied to clipboard

The CapturedRequest being processed.

Functions

Link copied to clipboard
fun addHeader(name: String, value: String)

Adds a single response header.

Link copied to clipboard
open override fun build(): ResponseDefinition<P, T>

Constructs a new instance of ResponseDefinition with the configured attributes of the builder.

Link copied to clipboard
fun delayMillis(millis: Long)

Sets a delay for the response in milliseconds.

Link copied to clipboard
fun httpStatus(status: Int)