Simple and concise HTTP client library for Scala

后端 未结 11 1827
梦如初夏
梦如初夏 2020-12-12 20:26

I need a mature HTTP client library that is idiomatic to scala, concise in usage, simple semantics. I looked at the Apache HTTP and the Scala Dispatch and numerous new libra

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 21:05

    Surprised that no one mentioned finagle here. It is super simple to use:

    import com.twitter.finagle.{Http, Service}
    import com.twitter.finagle.http
    import com.twitter.util.{Await, Future}
    
    object Client extends App {
      val client: Service[http.Request, http.Response] = Http.newService("www.scala-lang.org:80")
      val request = http.Request(http.Method.Get, "/")
      request.host = "www.scala-lang.org"
      val response: Future[http.Response] = client(request)
      Await.result(response.onSuccess { rep: http.Response =>
        println("GET success: " + rep)
      })
    }
    

    See quick start guid for more detail: https://twitter.github.io/finagle/guide/Quickstart.html

提交回复
热议问题