kohttp
  • Introduction
  • Core
    • Synchronous calls
      • GET
      • POST
      • PUT
      • HEAD
      • DELETE
      • PATCH
      • Generic requests
      • Upload files
    • Asynchronous calls
      • async GET
      • async POST
      • async PUT
      • async HEAD
      • async DELETE
      • async PATCH
      • async Generic requests
      • async Upload files
    • Response usage
    • Interceptors
    • Customisation
    • Experimental features
  • History
    • Changelog
Powered by GitBook
On this page
  • String.httpGet() extension
  • GET with request parameters
  • GET with header and cookies

Was this helpful?

  1. Core
  2. Synchronous calls

GET

Get requests can be made in two different ways. First one is string extension, second is via kotlin dsl.

String.httpGet() extension

val response: Response = "https://google.com/search?q=iphone".httpGet()

GET with request parameters

val response: Response = httpGet {
   host = "google.com"
   path = "/search"
   param {
       "q" to "iphone"
       "safe" to "off"
   }
}

or

val response: Response = httpGet {
   url("https://google.com/search")
   param {
       "q" to "iphone"
       "safe" to "off"
   }
}

GET with header and cookies

val response: Response = httpGet {
    host = "github.com"
    path = "/search"

    header {
        "username" to "rybalkinsd"
        "security-policy" to json {
            "base-uri" to "none"
            "expect-ct" to json {
                "max-age" to 2592000
                "report-uri" to "foo.com/bar"
            }
            "script-src" to listOf("github.com", "github.io")
        }

        cookie {
            "user_session" to "toFycNV"
            "expires" to "Fri, 21 Dec 2018 09:29:55 -0000"
        }
    }

    param { ... }
}
PreviousSynchronous callsNextPOST

Last updated 5 years ago

Was this helpful?