Package-level declarations

Core server, stub registration, and configuration.

Core server, stub registration, and configuration.

Core server, stub registration, and configuration.

Core server, stub registration, and configuration.

Types

Link copied to clipboard
class BuildingStep<P : Any>

Defines the building step for associating an inbound RequestSpecification with its corresponding response definition. This class is part of a fluent API used to define mappings between request specifications and their respective responses.

Link copied to clipboard

This annotation marks the Mokksy API that is considered experimental and is not subject to the general compatibility guarantees. The behaviour of such API may change, or the API may be removed completely in any further release.

Link copied to clipboard

API marked with this annotation is internal, and it is not intended to be used outside Mokksy. It could be modified or removed without any notice. Using it outside Mokksy could cause undefined behaviour and/or any unexpected effects.

Link copied to clipboard

A Java-friendly wrapper around BuildingStep that exposes respondsWith, respondsWithStream, and respondsWithSseStream as instance methods accepting Consumer instead of Kotlin suspend lambdas.

Link copied to clipboard

Java-friendly wrapper around RequestSpecificationBuilder that replaces Kotlin functional types with their java.util.function equivalents.

Link copied to clipboard

Java-friendly wrapper around ResponseDefinitionBuilder that returns this from every mutating method, enabling fluent chaining without Kotlin-specific idioms.

Link copied to clipboard

Java-friendly wrapper around StreamingResponseDefinitionBuilder that returns this from every mutating method, enabling fluent chaining without Kotlin-specific idioms.

Link copied to clipboard

Controls which requests are recorded in the dev.mokksy.mokksy.request.RequestJournal.

Link copied to clipboard
annotation class MokksyDsl

DSL marker for the Mokksy stub-definition DSL.

Link copied to clipboard
interface MokksyHandler

Minimal contract for embedding Mokksy stub handling into a Ktor application.

Link copied to clipboard
class MokksyServer @JvmOverloads constructor(host: String = DEFAULT_HOST, port: Int = 0, val configuration: ServerConfiguration, configurer: Application.() -> Unit = {}) : MokksyHandler

An embedded mock HTTP server for testing. Registers stubs for any HTTP method and verifies request expectations after the test.

Link copied to clipboard
data class ServerConfiguration @JvmOverloads constructor(val verbose: Boolean = false, val name: String? = "Mokksy", val journalMode: JournalMode = JournalMode.LEAN, val json: Json = Json { ignoreUnknownKeys = true }, val contentNegotiationConfigurer: (ContentNegotiationConfig) -> Unit = { it.json(json) })

Configuration for a MokksyServer instance.

Link copied to clipboard
object SseEvent

Java-friendly factory for creating ServerSentEvent instances without trailing nulls.

Link copied to clipboard

Fluent builder for ServerSentEvent.

Link copied to clipboard
data class StubConfiguration @JvmOverloads constructor(val name: String? = null, val eventuallyRemove: Boolean = false, val verbose: Boolean = false)

Configuration for a stub's lifecycle and logging behaviour.

Functions

Link copied to clipboard
inline fun <P : Any> MokksyServer.delete(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.delete with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.delete(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.delete with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.get(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.get with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.get(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.get with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.head(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.head with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.head(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.head with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.method(configuration: StubConfiguration, httpMethod: HttpMethod, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.method with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.method(name: String? = null, httpMethod: HttpMethod, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.method with an optional stub name. Infers P from the call site.

Link copied to clipboard
expect fun Mokksy(host: String = DEFAULT_HOST, port: Int = 0, verbose: Boolean = false, configurer: Application.() -> Unit = {}): MokksyServer

Creates a MokksyServer — idiomatic Kotlin entry point for all platforms.

actual fun Mokksy(host: String, port: Int, verbose: Boolean, configurer: Application.() -> Unit): MokksyServer

Creates a MokksyServer — idiomatic Kotlin entry point for all platforms.

actual fun Mokksy(host: String, port: Int, verbose: Boolean, configurer: Application.() -> Unit): MokksyServer

Creates a MokksyServer — idiomatic Kotlin entry point for all platforms.

actual fun Mokksy(host: String, port: Int, verbose: Boolean, configurer: Application.() -> Unit): MokksyServer

Creates a MokksyServer — idiomatic Kotlin entry point for all platforms.

Link copied to clipboard
fun Application.mokksy(server: MokksyHandler, path: String = "{...}")

Installs Mokksy request handling into this Application.

fun Route.mokksy(server: MokksyHandler, path: String = "{...}")

Mounts Mokksy request handling into this Route scope.

Link copied to clipboard
inline fun <P : Any> MokksyServer.options(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.options with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.options(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.options with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.patch(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.patch with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.patch(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.patch with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.post(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.post with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.post(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.post with an optional stub name. Infers P from the call site.

Link copied to clipboard
inline fun <P : Any> MokksyServer.put(configuration: StubConfiguration, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.put with a StubConfiguration. Infers P from the call site.

inline fun <P : Any> MokksyServer.put(name: String? = null, noinline block: RequestSpecificationBuilder<P>.() -> Unit): BuildingStep<P>

Reified shortcut for MokksyServer.put with an optional stub name. Infers P from the call site.

Link copied to clipboard
fun <P : Any, T : Any> BuildingStep<P>.respondsWith(responseType: Class<T>, configurer: Consumer<ResponseDefinitionBuilder<P, T>>)

Java-friendly overload for BuildingStep.respondsWith.

Link copied to clipboard

Java-friendly overload for BuildingStep.respondsWithStream.

Link copied to clipboard
fun MokksyServer.shutdown(gracePeriodMillis: Long = 500, timeoutMillis: Long = 1000)

Stops the Mokksy server, blocking until shutdown is complete.

fun MokksyServer.shutdown(gracePeriodMillis: Long = 500, timeoutMillis: Long = 1000, dispatcher: CoroutineDispatcher)

Stops the Mokksy server on the given dispatcher, blocking until shutdown is complete.

Link copied to clipboard

Starts the Mokksy server and blocks until the port is bound and ready to accept requests.

Starts the Mokksy server on the given dispatcher, blocking until the port is bound.