khttp: HTTP without the bullshit

khttp is a Mozilla Public License 2.0 licensed library, written in Kotlin, inspired by requests, for human beings.

Java is bad at HTTP. Really bad. The tools provided are functionally broken. Unfortunately, by extension, Kotlin is also bad at HTTP. Yet, more and more, the need to interact with APIs and perform basic HTTP requests shows up in programs, but the broken tools in Java make it a big fuss. This isn’t how it should be.

To combat this, libraries like Unirest have popped up, but they introduce massive amounts of overhead to just make a simple GET request.

khttp attempts to solve this problem, by mimicking the Python requests module. khttp uses only the org.json.json library and native Java. There’s nothing else. No bullshit.

val r = get("https://api.github.com/user", auth=BasicAuthorization("user", "pass"))
r.statusCode
// 200
r.headers["Content-Type"]
// "application/json; charset=utf-8"
r.text
// """{"type": "User"..."""
r.jsonObject
// org.json.JSONObject

See similar code, without khttp.

Feature support

khttp is ready for today’s web.

  • International domains and URLs
  • Sessions with cookie persistence
  • Basic authentication
  • Elegant key/value cookies
  • Automatic decompression
  • Unicode response bodies
  • Connection timeouts