Simple and concise HTTP client library for Scala

后端 未结 11 1826
梦如初夏
梦如初夏 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 20:55

    Two Six years after originally responding to this post, I would have a different answer.

    I've been using akka-http, a collaboration between the spray and akka teams. It's backed by Lightbend, tightly aligned with the akka async environment... it's the right tool for this job.

    0 讨论(0)
  • 2020-12-12 20:58

    ScalaJ-Http is a very simple synchronous http client

    https://github.com/scalaj/scalaj-http

    I'd recommend it if you need a no-ceremony barebones Scala client.

    0 讨论(0)
  • 2020-12-12 21:00

    A little late to the party here, but I've been impressed with spray-client.

    It's got a nice DSL for building requests, supports both sync and async execution, as well as a variety of (un)marshalling types (JSON, XML, forms). It plays very nicely with Akka, too.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-12 21:05

    I've used Dispatch, Spray Client and the Play WS Client Library...None of them were simply to use or configure. So I created a simpler HTTP Client library which lets you perform all the classic HTTP requests in simple one-liners.

    See an example:

    import cirrus.clients.BasicHTTP.GET
    
    import scala.concurrent.Await
    import scala.concurrent.duration._
    
    object MinimalExample extends App {
    
      val html = Await.result(Cirrus(GET("https://www.google.co.uk")), 3 seconds)
    
      println(html)
    }
    

    ... produces ...

    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB">...</html>
    

    The library is called Cirrus and is available via Maven Central

    libraryDependencies += "com.github.godis" % "cirrus_2.11" % "1.4.1"
    

    The documentation is available on GitHub

    https://github.com/Godis/Cirrus
    
    0 讨论(0)
提交回复
热议问题