Request

class Request(url: String)

Represents a request builder Example usage:

Request()
.protocol(RequestProtocol.HTTPS)
.host("google.com")
.path("/search")
.parameter("q", "Hello World")
.send()

or

Request("https://google.com/search?q=Hello%20World")
.send()

Constructors

Link copied to clipboard
constructor(url: String)

Properties

Link copied to clipboard

The body of the request Default: null (No body is sent)

Link copied to clipboard

Follow redirects Default: true

Link copied to clipboard

The headers of the request Default: User-Agent, Accept

Link copied to clipboard

The host of the server

Link copied to clipboard

The maximum number of redirects to follow Default: -1

Link copied to clipboard

The request method Default: GET

Link copied to clipboard

The parameters of the request Default: Empty map

Link copied to clipboard
var path: String?

The path of the request Default: null (No path)

Link copied to clipboard
var port: Int?

The port of the server Default: null (No port)

Link copied to clipboard

The protocol to use (http, https) Default: https

Link copied to clipboard

The timeout for reading the response in millisecond Default: 0 (No timeout)

Link copied to clipboard

The timeout of the request in millisecond Default: 0 (No timeout)

Functions

Link copied to clipboard
fun addHeader(key: String, value: String): Request

Adds a header to the request, it doesn't override the value if the key already exists

Link copied to clipboard

Adds the given headers to the request, it doesn't override the value if the key already exists

Link copied to clipboard
fun addParameter(key: String, value: String): Request

Adds a parameter to the request, it doesn't override the value if the key already exists

Link copied to clipboard
fun addParameters(parameters: Map<String, String>): Request

Adds the given parameters to the request, it doesn't override the value if the key already exists

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

Sets the body of the request

Link copied to clipboard

Sets the request method to 'DELETE' and sends the request

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Checks if this request is equal to another request

Link copied to clipboard
fun followRedirects(followRedirects: Boolean): Request

Sets the follow redirects option

Link copied to clipboard

Sets the form body of the request

Link copied to clipboard
fun get(): Response

Sets the request method to 'GET' and sends the request

Link copied to clipboard
open override fun hashCode(): Int

Returns the hash code of this request

Link copied to clipboard
fun head(): Response

Sets the request method to 'HEAD' and sends the request

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

Sets a header to the request, it also overrides the value if the key already exists

Link copied to clipboard
fun headers(headers: Map<String, String>): Request

Sets the given headers to the request, it also overrides the value if the key already exists

Link copied to clipboard
fun host(host: String): Request

Sets the host of the request

Link copied to clipboard
fun jsonBody(body: JsonElement): Request

Sets the json body of the request

Link copied to clipboard
fun maxRedirects(maxRedirects: Int): Request

Sets the maximum amount of redirects to follow

Link copied to clipboard

Sets the request method

Link copied to clipboard

Sets the request method to 'OPTIONS' and sends the request

Link copied to clipboard
fun parameter(key: String, value: String): Request

Sets a parameter to the request, it also overrides the value if the key already exists

Link copied to clipboard
fun parameters(parameters: Map<String, String>): Request

Sets the given parameters to the request, it also overrides the value if the key already exists

Link copied to clipboard

Sets the request method to 'PATCH' and sends the request

Link copied to clipboard
fun path(path: String): Request

Sets the path of the request

Link copied to clipboard
fun port(port: Int): Request

Sets the port of the request

Link copied to clipboard
fun post(): Response

Sets the request method to 'POST' and sends the request

Link copied to clipboard

Sets the protocol of the request

Link copied to clipboard
fun put(): Response

Sets the request method to 'PUT' and sends the request

Link copied to clipboard
fun readTimeout(readTimeout: Int): Request

Sets the read timeout of the request

Link copied to clipboard

Sends the request

Link copied to clipboard
fun timeout(timeout: Int): Request

Sets the timeout of the request

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Turns this request information (protocol, host, port, path and params) into a url string