class DefaultRequest

Sets default request parameters. Used to add common headers and URL for a request. Note that trailing slash in base URL and leading slash in request URL are important. The rules to calculate a final URL:

  1. Request URL doesn't start with slash

    • Base URL ends with slash -> concat strings. Example: base =, request = file.html, result =

    • Base URL doesn't end with slash -> remove last path segment of base URL and concat strings. Example: base =, request = file.html, result =

  2. Request URL starts with slash -> use request path as is. Example: base =, request = /root/file.html, result =

Headers of the builder will be pre-populated with request headers. You can use HeadersBuilder.contains, HeadersBuilder.appendIfNameAbsent and HeadersBuilder.appendIfNameAndValueAbsent to avoid appending some header twice.


val client = HttpClient {
defaultRequest {
headers.appendIfNameAbsent(HttpHeaders.ContentType, ContentType.Application.Json)
// <- requests "https://base.url/dir/file", ContentType = Application.Json
// <- requests "https://base.url/other_root/file", ContentType = Application.Json
// <- requests "", ContentType = Application.Json
client.get("https://some.url") { HttpHeaders.ContentType = ContentType.Application.Xml }
// <- requests "https://some.url/", ContentType = Application.Xml


Link copied to clipboard
class DefaultRequestBuilder : HttpMessageBuilder

Configuration object for DefaultRequestBuilder plugin

Link copied to clipboard