ktor-client-mock / io.ktor.client.engine.mock

Package io.ktor.client.engine.mock

Types

MockEngine

class MockEngine : HttpClientEngineBase

HttpClientEngine for writing tests without network.

MockEngineConfig

class MockEngineConfig : HttpClientEngineConfig

HttpClientEngineConfig for MockEngine.

MockRequestHandleScope

class MockRequestHandleScope

Scope for MockRequestHandler.

Type Aliases

MockRequestHandler

typealias MockRequestHandler = suspend MockRequestHandleScope.(request: HttpRequestData) -> HttpResponseData

Single HttpClientCall to HttpResponse mapper.

Extensions for External Classes

io.ktor.http.content.OutgoingContent

Functions

respond

fun MockRequestHandleScope.respond(content: String, status: HttpStatusCode = HttpStatusCode.OK, headers: Headers = headersOf()): HttpResponseData

Send response with specified string content, status and headers.

fun MockRequestHandleScope.respond(content: ByteArray, status: HttpStatusCode = HttpStatusCode.OK, headers: Headers = headersOf()): HttpResponseData

Send response with specified bytes content, status and headers.

fun MockRequestHandleScope.respond(content: ByteReadChannel, status: HttpStatusCode = HttpStatusCode.OK, headers: Headers = headersOf()): HttpResponseData

Send response with specified ByteReadChannel, status and headers.

respondBadRequest

fun MockRequestHandleScope.respondBadRequest(): HttpResponseData

Send HttpStatusCode.BadRequest response.

respondError

fun MockRequestHandleScope.respondError(status: HttpStatusCode, content: String = status.description, headers: Headers = headersOf()): HttpResponseData

Send error response.

respondOk

fun MockRequestHandleScope.respondOk(content: String = ""): HttpResponseData

Send ok response.

respondRedirect

fun MockRequestHandleScope.respondRedirect(location: String = ""): HttpResponseData

Respond redirect with location in Location header.