Request

open class Request(url: String, method: String, headers: Map<String, String>, body: dynamic, referrer: String?, referrerPolicy: dynamic, mode: RequestMode?, credentials: RequestCredentials?, cache: RequestCache?, redirect: RequestRedirect?, integrity: String?, keepalive: Boolean?, reqWindow: Any?, middlewares: List<Middleware>)

Represents the common fields and attributes of an HTTP request.

Use it to define common headers, error-handling, base url, etc. for a specific API for example. By calling one of the executing methods like get or post a specific request is built from the template and send to the server.

Constructors

Link copied to clipboard
fun Request(url: String = "", method: String = "", headers: Map<String, String> = emptyMap(), body: dynamic = undefined, referrer: String? = undefined, referrerPolicy: dynamic = undefined, mode: RequestMode? = undefined, credentials: RequestCredentials? = undefined, cache: RequestCache? = undefined, redirect: RequestRedirect? = undefined, integrity: String? = undefined, keepalive: Boolean? = undefined, reqWindow: Any? = undefined, middlewares: List<Middleware> = emptyList())

Functions

Link copied to clipboard
fun accept(value: String): Request

adds the given Accept value to the http headers, e.g "application/pdf"

Link copied to clipboard
fun acceptJson(): Request

adds a header to accept JSON as response

Link copied to clipboard
fun append(subUrl: String): Request

appends the given subUrl to the url

Link copied to clipboard
fun arrayBuffer(content: ArrayBuffer): Request

sets the ArrayBuffer content to the request

Link copied to clipboard
fun basicAuth(username: String, password: String): Request

adds the basic Authorization header for the given username and password

Link copied to clipboard
fun blob(content: Blob): Request

sets the Blob content to the request

Link copied to clipboard
fun body(content: String): Request

sets the body content to the request

Link copied to clipboard
fun cache(value: RequestCache): Request

sets the cache property of the Request

Link copied to clipboard
fun cacheControl(value: String): Request

adds the given Cache-Control value to the http headers

Link copied to clipboard
suspend fun connect(subUrl: String? = null): Response

issues a connect request returning a flow of it's response

Link copied to clipboard
fun contentType(value: String): Request

adds the given Content-Type value to the http headers

Link copied to clipboard
open fun copy(url: String = this.url, method: String = this.method, headers: Map<String, String> = this.headers, body: dynamic = this.body, referrer: String? = this.referrer, referrerPolicy: dynamic = this.referrerPolicy, mode: RequestMode? = this.mode, credentials: RequestCredentials? = this.credentials, cache: RequestCache? = this.cache, redirect: RequestRedirect? = this.redirect, integrity: String? = this.integrity, keepalive: Boolean? = this.keepalive, reqWindow: Any? = this.reqWindow, middlewares: List<Middleware> = this.middlewares): Request

creates a copy of the Request.

Link copied to clipboard
fun credentials(value: RequestCredentials): Request

sets the credentials property of the Request

Link copied to clipboard
open suspend fun delete(subUrl: String? = null): Response

issues a delete request returning a flow of it's response

Link copied to clipboard
suspend fun execute(): Response

executes the HTTP call and sends it to the server, awaits the response (async) and returns a Response. When request failed a FetchException will be thrown.

Link copied to clipboard
fun formData(content: FormData): Request

sets the FormData content to the request

Link copied to clipboard
suspend fun get(subUrl: String? = null): Response

issues a get request returning a flow of it's response

Link copied to clipboard
suspend fun head(subUrl: String? = null): Response

issues a head request returning a flow of it's response

Link copied to clipboard
fun header(name: String, value: String): Request

adds the given http header to the request

Link copied to clipboard
fun integrity(value: String): Request

sets the integrity property of the Request

Link copied to clipboard
fun keepalive(value: Boolean): Request

sets the keepalive property of the Request

Link copied to clipboard
suspend fun options(subUrl: String? = null): Response

issues a options request returning a flow of it's response

Link copied to clipboard
suspend fun patch(subUrl: String? = null): Response

issues a patch request returning a flow of it's response

Link copied to clipboard
suspend fun post(subUrl: String? = null): Response

issues a post request returning a flow of it's response

Link copied to clipboard
suspend fun put(subUrl: String? = null): Response

issues a put request returning a flow of it's response

Link copied to clipboard
fun redirect(value: RequestRedirect): Request

sets the redirect property of the Request

Link copied to clipboard
fun referrer(value: String): Request

sets the referrer property of the Request

Link copied to clipboard
fun referrerPolicy(value: dynamic): Request

sets the referrerPolicy property of the Request

Link copied to clipboard
fun requestMode(value: RequestMode): Request

sets the requestMode property of the Request

Link copied to clipboard
fun reqWindow(value: Any): Request

sets the reqWindow property of the Request

Link copied to clipboard
fun use(middleware: Middleware): Request

adds an Middleware to handle all requests and responses.

fun use(vararg middlewares: Middleware): Request

adds Middlewares to handle all requests and responses.

Properties

Link copied to clipboard
val body: dynamic
Link copied to clipboard
val cache: RequestCache?
Link copied to clipboard
val credentials: RequestCredentials?
Link copied to clipboard
val headers: Map<String, String>
Link copied to clipboard
val integrity: String?
Link copied to clipboard
val keepalive: Boolean?
Link copied to clipboard
val method: String
Link copied to clipboard
val middlewares: List<Middleware>
Link copied to clipboard
val mode: RequestMode?
Link copied to clipboard
val redirect: RequestRedirect?
Link copied to clipboard
val referrer: String?
Link copied to clipboard
val referrerPolicy: dynamic
Link copied to clipboard
val reqWindow: Any?
Link copied to clipboard
val url: String