Request

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

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

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

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

sets the cache property of the Request

Link copied to clipboard

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

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

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

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

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

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
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val referrerPolicy: dynamic
Link copied to clipboard
Link copied to clipboard
val url: String