square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.88k stars 9.16k forks source link

Kotlin operator for HttpUrl #7233

Closed yschimke closed 2 years ago

yschimke commented 2 years ago

Inspired by Okio Path

    val aiortc = "https://cloudflare-quic.com/b/".toHttpUrl()

    val postRequest =
      Request(
        url = aiortc + "post",
        body = "{}".toRequestBody("application/json".toMediaType())
      )
private operator fun HttpUrl.plus(link: String): HttpUrl {
  return this.resolve(link)!!
}
JakeWharton commented 2 years ago

Resolve is not necessarily additive, though. This is surprising: "http://foo.com/bar".toHttpUrl() + "/baz".

swankjesse commented 2 years ago

Yeah, also the way this interacts with queries could be surprising. I think the most tempting options are [] accessors for path segments or query parameters, and I think that’s also a tough sell cause it's not necessary obvious which applies where.

yschimke commented 2 years ago

Makes sense, thought it worth asking.