├── .github └── workflows │ └── scala.yml ├── .gitignore ├── .scala-steward.conf ├── .scalafmt.conf ├── README.md ├── build.sbt ├── dispatch └── src │ └── main │ └── scala │ └── dispatch │ └── Dispatch.scala ├── gigahorse └── src │ └── main │ └── scala │ └── gigahorse │ └── GigahorseClient.scala ├── hammock └── src │ └── main │ └── scala │ └── hammock │ └── hammockClient.scala ├── http4s └── src │ └── main │ └── scala │ └── http4s │ └── Http4s.scala ├── play └── src │ └── main │ └── scala │ └── play │ └── Play.scala ├── project ├── build.properties └── plugins.sbt ├── requests-scala └── src │ └── main │ └── scala │ └── Requests.scala ├── scalaj └── src │ └── main │ └── scala │ └── scalaj │ └── SimplifiedHttp.scala └── sttp └── src └── main └── scala └── Hello.scala /.github/workflows/scala.yml: -------------------------------------------------------------------------------- 1 | name: Scala CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - uses: sbt/setup-sbt@v1 17 | - uses: actions/setup-java@v4 18 | with: 19 | distribution: 'temurin' 20 | java-version: '21' 21 | - name: Run tests 22 | run: sbt compile 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /logs/ 2 | /project/*-shim.sbt 3 | /project/project/ 4 | /project/target/ 5 | /target/ 6 | **/target 7 | .idea/ 8 | .metals/ 9 | .bloop/ 10 | project/.bloop/ 11 | project/metals.sbt 12 | .bsp/ 13 | .vscode/ -------------------------------------------------------------------------------- /.scala-steward.conf: -------------------------------------------------------------------------------- 1 | pullRequests.frequency = "@weekly" 2 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version = "3.0.0" 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Scala CI](https://github.com/mfirry/scala-http-clients/workflows/Scala%20CI/badge.svg) 2 | [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) 3 | 4 | Raise your hand if you need a scala http client. 5 | 6 | | Name | Version | License | Github Stars | 7 | |----------------------------------------------------|---------|-----------------------------------------------------------------------------|-------------------------------------------------------------------| 8 | | [dispatch](https://github.com/dispatch/reboot) | 1.2.0 | ![GitHub](https://img.shields.io/github/license/dispatch/reboot) | ![GitHub](https://img.shields.io/github/stars/dispatch/reboot) | 9 | | [gigahorse](https://github.com/eed3si9n/gigahorse) | 0.5.0 | ![GitHub](https://img.shields.io/github/license/eed3si9n/gigahorse) | ![GitHub](https://img.shields.io/github/stars/eed3si9n/gigahorse) | 10 | | [Simplified Http]() | 2.4.2 | ![GitHub](https://img.shields.io/github/license/scalaj/scalaj-http) | ![GitHub](https://img.shields.io/github/stars/scalaj/scalaj-http) | 11 | | [sttp](https://github.com/softwaremill/sttp) | 3.9.7 | ![GitHub](https://img.shields.io/github/license/softwaremill/sttp) | ![GitHub](https://img.shields.io/github/stars/softwaremill/sttp) | 12 | | [naive-http]() | v126 | ![GitHub](https://img.shields.io/github/license/timt/naive-http) | ![GitHub](https://img.shields.io/github/stars/timt/naive-http) | 13 | | [http4s](https://github.com/http4s/http4s) | 0.23.6 | ![GitHub](https://img.shields.io/github/license/http4s/http4s) | ![GitHub]( https://img.shields.io/github/stars/http4s/http4s) | 14 | | [play-ws]() | 2.1.3 | ![GitHub](https://img.shields.io/github/license/play/play) | ![GitHub](https://img.shields.io/github/stars/play/play) | 15 | | [Requests-Scala]() | 0.9.0 | ![GitHub](https://img.shields.io/github/license/com-lihaoyi/requests-scala) | ![GitHub](https://img.shields.io/github/stars/scalatra/scalatra) | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | name := """scala-http-clients""" 2 | 3 | version := "1.2.13.15" 4 | 5 | ThisBuild / scalafmtOnCompile := true 6 | 7 | val scalaV = "2.13.16" 8 | 9 | lazy val dispatch = 10 | (project in file("dispatch")) 11 | .settings( 12 | scalaVersion := scalaV, 13 | libraryDependencies ++= Seq( 14 | "org.dispatchhttp" %% "dispatch-core" % "2.0.0" 15 | ) 16 | ) 17 | 18 | lazy val gigahorse = 19 | (project in file("gigahorse")) 20 | .settings( 21 | scalaVersion := scalaV, 22 | libraryDependencies ++= Seq( 23 | "com.eed3si9n" %% "gigahorse-core" % "0.9.3", 24 | "com.eed3si9n" %% "gigahorse-asynchttpclient" % "0.9.3" 25 | ) 26 | ) 27 | 28 | lazy val http4s = 29 | (project in file("http4s")) 30 | .settings( 31 | scalaVersion := scalaV, 32 | libraryDependencies ++= Seq( 33 | "org.http4s" %% "http4s-dsl" % "0.23.9", 34 | "org.http4s" %% "http4s-blaze-client" % "0.23.9" 35 | ) 36 | ) 37 | 38 | lazy val play = 39 | (project in file("play")) 40 | .settings( 41 | scalaVersion := scalaV, 42 | libraryDependencies ++= Seq( 43 | "com.typesafe.play" %% "play-ahc-ws-standalone" % "2.1.3", 44 | "com.typesafe.play" %% "play-ws-standalone-json" % "2.1.3" 45 | ) 46 | ) 47 | 48 | lazy val scalaj = 49 | (project in file("scalaj")) 50 | .settings( 51 | scalaVersion := scalaV, 52 | libraryDependencies ++= Seq( 53 | "org.scalaj" %% "scalaj-http" % "2.4.2" 54 | ) 55 | ) 56 | 57 | lazy val `naive-http` = 58 | (project in file("naive-http")) 59 | .settings( 60 | scalaVersion := scalaV, 61 | libraryDependencies ++= Seq( 62 | "io.shaka" %% "naive-http" % "126" 63 | ), 64 | resolvers += ("Tim Tennant's repo" at "http://dl.bintray.com/timt/repo/") 65 | .withAllowInsecureProtocol(true) 66 | ) 67 | 68 | lazy val sttp = 69 | (project in file("sttp")) 70 | .settings( 71 | scalaVersion := scalaV, 72 | libraryDependencies ++= Seq( 73 | "com.softwaremill.sttp.client3" %% "core" % "3.9.7" 74 | ) 75 | ) 76 | 77 | lazy val requests = 78 | (project in file("requests-scala")) 79 | .settings( 80 | scalaVersion := scalaV, 81 | libraryDependencies ++= Seq( 82 | "com.lihaoyi" %% "requests" % "0.9.0" 83 | ) 84 | ) 85 | 86 | lazy val root = project 87 | .in(file(".")) 88 | .aggregate( 89 | dispatch, 90 | gigahorse, 91 | http4s, 92 | play, 93 | requests, 94 | scalaj, 95 | sttp 96 | ) 97 | -------------------------------------------------------------------------------- /dispatch/src/main/scala/dispatch/Dispatch.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import scala.language.postfixOps 4 | 5 | import dispatch._, Defaults._ 6 | 7 | import scala.concurrent.{Await, Future} 8 | import scala.concurrent.duration._ 9 | 10 | // https://dispatchhttp.org 11 | object Dispatch { 12 | 13 | def main(args: Array[String]): Unit = { 14 | 15 | val header = Map("User-Agent" -> "Awesome-Octocat-App") 16 | val github = 17 | url("https://api.github.com/users/scala-italy") appendHeaders header 18 | 19 | val x = Await.result(Http.default(github OK as.String), 1 second) 20 | println(x) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /gigahorse/src/main/scala/gigahorse/GigahorseClient.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import scala.concurrent._ 4 | import scala.concurrent.duration._ 5 | import gigahorse._ 6 | import gigahorse.support.asynchttpclient.Gigahorse 7 | import gigahorse.HeaderNames 8 | 9 | // https://github.com/eed3si9n/gigahorse 10 | object GigahorseClient { 11 | 12 | def main(args: Array[String]): Unit = { 13 | Gigahorse.withHttp(Gigahorse.config) { http => 14 | val r = Gigahorse 15 | .url("https://api.github.com/users/scala-italy") 16 | .get 17 | .addHeaders( 18 | HeaderNames.USER_AGENT -> "Awesome-Octocat-App" 19 | ) 20 | val f = http.run(r) 21 | val res = Await.result(f, 120.seconds) 22 | println(res.bodyAsString) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /hammock/src/main/scala/hammock/hammockClient.scala: -------------------------------------------------------------------------------- 1 | package hammock 2 | 3 | import cats.effect.IO 4 | 5 | import cats.effect.IO 6 | import io.circe.generic.auto._ 7 | import hammock._ 8 | import hammock.marshalling._ 9 | import hammock.apache.ApacheInterpreter 10 | import hammock.circe.implicits._ 11 | 12 | object hammockClient extends App { 13 | implicit val interpreter = ApacheInterpreter[IO] 14 | 15 | val response = Hammock 16 | .request( 17 | Method.GET, 18 | uri"https://api.github.com/users/scala-italy", 19 | Map("User-Agent" -> "Awesome-Octocat-App") 20 | ) 21 | .exec[IO] 22 | .unsafeRunSync 23 | 24 | println(response) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /http4s/src/main/scala/http4s/Http4s.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import java.util.concurrent._ 4 | 5 | import cats.effect._ 6 | 7 | import org.typelevel.ci._ 8 | import org.http4s.{Header, Http, Request, Response, Uri} 9 | import org.http4s.Method.GET 10 | import org.http4s._ 11 | import org.http4s.client._ 12 | import org.http4s.implicits._ 13 | 14 | // http://http4s.org/ 15 | object Http4s extends cats.effect.IOApp { 16 | 17 | def run(args: List[String]): IO[ExitCode] = { 18 | val blockingPool = Executors.newFixedThreadPool(5) 19 | val httpClient: Client[IO] = JavaNetClientBuilder[IO].create 20 | 21 | val uri = uri"https://api.github.com/users/scala-italy" 22 | 23 | httpClient 24 | .expect[String]( 25 | Request[IO](method = GET, uri = uri) 26 | .withHeaders(Header.Raw(ci"User-Agent", "Awesome-Octocat-App")) 27 | ) 28 | .as(ExitCode.Success) 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /play/src/main/scala/play/Play.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import scala.language.postfixOps 4 | 5 | import scala.concurrent.ExecutionContext.Implicits.global 6 | import scala.concurrent.{Await, Future} 7 | import scala.concurrent.duration._ 8 | import play.shaded.ahc.org.asynchttpclient._ 9 | import play.api.libs.ws._ 10 | import play.api.libs.ws.ahc.{AhcConfigBuilder, StandaloneAhcWSClient} 11 | 12 | // https://playframework.com 13 | object Play { 14 | 15 | def main(args: Array[String]): Unit = { 16 | val ahcConfig = new AhcConfigBuilder().build() 17 | val w = new DefaultAsyncHttpClient(ahcConfig) 18 | val url = "https://api.github.com/users/scala-italy" 19 | val ws = new StandaloneAhcWSClient(w)(null) 20 | val res = 21 | ws.url(url).addHttpHeaders("User-Agent" -> "Awesome-Octocat-App").get 22 | 23 | val x = Await.result(res, 1 second) 24 | println(x.body) 25 | ws.close 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.10.11 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") 2 | 3 | addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") 4 | 5 | addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.2.9") 6 | -------------------------------------------------------------------------------- /requests-scala/src/main/scala/Requests.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | object Requests { 4 | def main(args: Array[String]): Unit = { 5 | val r = requests.get("https://api.github.com/users/scala-italy") 6 | 7 | println(r.text) 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /scalaj/src/main/scala/scalaj/SimplifiedHttp.scala: -------------------------------------------------------------------------------- 1 | package com.example 2 | import scalaj.http.Http 3 | 4 | // https://github.com/scalaj/scalaj-http 5 | object SimplifiedHttp extends App { 6 | 7 | val response = Http("https://api.github.com/users/scala-italy") 8 | .header("User-Agent", "Awesome-Octocat-App") 9 | .asString 10 | 11 | println(response.body) 12 | } 13 | -------------------------------------------------------------------------------- /sttp/src/main/scala/Hello.scala: -------------------------------------------------------------------------------- 1 | import sttp.client3._ 2 | 3 | object Hello extends App { 4 | val backend = HttpURLConnectionBackend() 5 | val response = basicRequest 6 | .get(uri"https://api.github.com/users/scala-italy") 7 | .send(backend) 8 | println(response) 9 | } 10 | --------------------------------------------------------------------------------