Gigahorse は、Scala のための HTTP クライアントで複数のバックエンド実装をサポートする。 内部実装として Apache HttpComponents か Async Http Client か Square OkHttp か Akka HTTP から選ぶことができる。
Apache HTTP HttpComponents を使う場合:
libraryDependencies += "com.eed3si9n" %% "gigahorse-apache-http" % "0.8.0"
Async HTTP Client を使う場合:
libraryDependencies += "com.eed3si9n" %% "gigahorse-asynchttpclient" % "0.8.0"
Square OkHttp 3.x を使う場合:
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.8.0"
Akka HTTP は現段階では実験的サポート:
libraryDependencies += "com.eed3si9n" %% "gigahorse-akka-http" % "0.8.0"
Apache v2
Gigahorse を使った簡単な GET 呼び出しの例をみてみよう:
scala> import gigahorse.*, support.apachehttp.Gigahorse
scala> import scala.concurrent.*, duration.*
scala> val http = Gigahorse.http(Gigahorse.config)
val http: gigahorse.HttpClient = gigahorse.support.apachehttp.ApacheHttpClient@6e571cd9
scala> val r = Gigahorse.url("https://api.frankfurter.dev/v1/latest").get.addQueryString("base" -> "USD")
val r: gigahorse.Request = Request(https://api.frankfurter.dev/v1/latest, GET, EmptyBody(), Map(), Map(base -> List(USD)), None, None, None, None, None, None)
scala> val f = http.run(r, Gigahorse.asString)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
val f: scala.concurrent.Future[String] = Future(<not completed>)
scala> Await.result(f, 120.seconds)
val res0: String = {"amount":1.0,"base":"USD","date":"2025-04-11","rates":{"AUD":1.6042,"BGN":1.7238,"BRL":5.831,"CAD":1.3869,"CHF":0.81544,"CNY":7.2994,"CZK":22.164,"DKK":6.5816,"EUR":0.88137,"GBP":0.76395,"HKD":7.7552,"HUF":360.39,"IDR":16855,"ILS":3.7209,"INR":86.09,"ISK":128.06,"JPY":142.84,"KRW":1431.68,"MXN":20.38,"MYR":4.4225,"NOK":10.665,"NZD":1.7254,"PHP":57.065,"PLN":3.7857,"RON":4.3872,"SEK":9.8006,"SGD":1.3213,"THB":33.555,"TRY":38.058,"ZAR":19.2834}}
scala> http.close()