Package-level declarations

Types

Link copied to clipboard

A class which can be used to abort an API request after it was made.

Link copied to clipboard

Default values for fetch (or methods that delegate to fetch).

Link copied to clipboard

A class with a slightly friendlier API than using Window.fetch directly by providing HTTP method helper methods.

Link copied to clipboard
Link copied to clipboard
sealed class RequestBody

Body contents that can be set when calling fetch.

Link copied to clipboard
class ResponseBytesException(val response: Response, val bodyBytes: ByteArray?, cause: Throwable? = null) : Exception

An exception that gets thrown if we receive a response whose body cannot be converted into raw bytes.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
suspend fun Response.bodyAsBytes(requireOk: Boolean = true): ByteArray

Returns the current body of the target Response.

Link copied to clipboard
fun bodyOf(json: Json): RequestBody
fun bodyOf(params: URLSearchParams): RequestBody
fun bodyOf(blob: Blob): RequestBody
fun bodyOf(formData: FormData): RequestBody
fun bodyOf(bytes: ByteArray, contentType: String = "application/octet-stream"): RequestBody
fun bodyOf(buffer: ArrayBuffer, contentType: String = "application/octet-stream"): RequestBody

fun bodyOf(text: String, contentType: String = "text/plain"): RequestBody

Create a text body.

Link copied to clipboard
suspend fun WindowOrWorkerGlobalScope.fetch(method: HttpMethod, resource: String, body: RequestBody? = null, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): Response

A Kotlin-idiomatic version of the standard library's WindowOrWorkerGlobalScope.fetch function.

Link copied to clipboard
suspend fun WindowOrWorkerGlobalScope.fetchBytes(method: HttpMethod, resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: ByteArray? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

A convenience method for fetch built around the common case of sending / receiving raw bytes.

Link copied to clipboard
suspend fun WindowOrWorkerGlobalScope.tryFetch(method: HttpMethod, resource: String, body: RequestBody? = null, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, logOnError: Boolean = false, abortController: AbortController? = null): Response?

A convenience version of fetch that returns null instead of throwing if the request fails.

suspend fun <T> WindowOrWorkerGlobalScope.tryFetch(method: HttpMethod, resource: String, body: RequestBody? = null, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, logOnError: Boolean = false, abortController: AbortController? = null, transform: suspend Response.() -> T): T?

A convenience version of fetch that safely converts the initial request into some target object of type T.

Link copied to clipboard
suspend fun WindowOrWorkerGlobalScope.tryFetchBytes(method: HttpMethod, resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: ByteArray? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, logOnError: Boolean = false, abortController: AbortController? = null): ByteArray?

Like fetchBytes but returns null if the fetch fails or the body can't be read.