HttpFetcher

class HttpFetcher(window: Window)(source)

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

For example:

// Without HttpFetcher
window.fetch(HttpMethod.GET, "/some/api/path")

// With HttpFetcher
window.http.get("/some/api/path")
// ... or a version that won't throw exceptions
// window.http.tryGet("/some/api/path")

The class additionally exposes a logOnError field which globally applies to all try... methods.

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(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray

Call DELETE on a target resource.

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

Call DELETE on a target resource, returning the response body as a raw array of bytes.

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

Call GET on a target resource.

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

Call GET on a target resource, returning the response body as a raw array of bytes.

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

Call HEAD on a target resource.

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

Call HEAD on a target resource, returning the response body as a raw array of bytes.

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

Call OPTIONS on a target resource.

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

Call OPTIONS on a target resource, returning the response body as a raw array of bytes.

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

Call PATCH on a target resource.

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

Call PATCH on a target resource, returning the response body as a raw array of bytes.

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

Call POST on a target resource.

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

Call POST on a target resource, returning the response body as a raw array of bytes.

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

Call PUT on a target resource.

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

Call PUT on a target resource, returning the response body as a raw array of bytes.

Link copied to clipboard
suspend fun tryDelete(resource: 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 tryDeleteBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryGet(resource: 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 tryGetBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryHead(resource: 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 tryHeadBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryOptions(resource: 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 tryOptionsBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryPatch(resource: 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 tryPatchBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: ByteArray? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryPost(resource: 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 tryPostBytes(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: ByteArray? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null): ByteArray?

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

Link copied to clipboard
suspend fun tryPut(resource: 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.

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

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