ApiFetcher

class ApiFetcher(window: Window)(source)

A class which makes it easier to access a Kobweb API endpoint, instead of using Window.fetch directly.

This class works by wrapping Window.http but specifically for Kobweb API calls (URLs which are prefixed with "/api/").

Constructors

Link copied to clipboard
constructor(window: Window)

Properties

Link copied to clipboard

If true, when using any of the "try" methods, log any errors, if they occur, to the console.

Functions

Link copied to clipboard
suspend fun delete(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

Call DELETE on a target API path.

Link copied to clipboard
suspend fun get(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

Call GET on a target API path.

Link copied to clipboard
suspend fun head(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

Call HEAD on a target API path.

Link copied to clipboard
suspend fun options(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

Call OPTIONS on a target API path.

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

Call PATCH on a target API path.

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

Call POST on a target API path.

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

Call PUT on a target API path.

Link copied to clipboard
suspend fun tryDelete(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

Like delete, but returns null if the request failed for any reason.

Link copied to clipboard
suspend fun tryGet(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

Like get, but returns null if the request failed for any reason.

Link copied to clipboard
suspend fun tryHead(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

Like head, but returns null if the request failed for any reason.

Link copied to clipboard
suspend fun tryOptions(apiPath: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

Like options, but returns null if the request failed for any reason.

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

Like patch, but returns null if the request failed for any reason.

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

Like post, but returns null if the request failed for any reason.

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

Like put, but returns null if the request failed for any reason.