respondsWith

fun <T : Any> respondsWith(responseType: Class<T>, configurer: Consumer<JavaResponseDefinitionBuilder<P, T>>)(source)

Configures a typed response for this stub.

Parameters

responseType

The Java Class of the response type.

configurer

Type Parameters

T

The type of the response body.


Configures a String response for this stub.

Shorthand for respondsWith(String.class, configurer).

Parameters

configurer

Configures a simple String response body for this stub with HTTP 200.

Shorthand for respondsWith(builder -> builder.body(body)):

mokksy.get("/hello").respondsWith("Hello, World!");

Parameters

body

The response body string.


fun respondsWith(body: String, statusCode: Int)(source)

Configures a simple String response body with a custom HTTP status code.

Shorthand for respondsWith(builder -> builder.body(body).status(statusCode)):

mokksy.post("/items").respondsWith("{\"id\":42}", 201);

Parameters

body

The response body string.

statusCode

The HTTP status code, e.g. 201, 400.