Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Last active March 20, 2019 18:14
Show Gist options
  • Save yasuabe/042bc28df9cb41cff165278492bc074d to your computer and use it in GitHub Desktop.
Save yasuabe/042bc28df9cb41cff165278492bc074d to your computer and use it in GitHub Desktop.
a simple example of hammock http client with Cats Effect IO and Apache HttpComponents Client
package qiita_sample1
import cats.effect.{ExitCode, IO, IOApp}
import cats.free.Free
import hammock._
import hammock.apache.ApacheInterpreter
object SimpleMain extends IOApp {
val program: Free[HttpF, HttpResponse] = Hammock
.request(Method.GET, uri"http://httpbin.org/get", Map())
implicit val interpreter: InterpTrans[IO] = ApacheInterpreter[IO]
def run(args: List[String]): IO[ExitCode] = for {
res <- program.exec[IO]
_ <- IO(println(res.entity))
} yield ExitCode.Success
}
// ---- build.sbt ----
//name := "hammock_test"
//
//version := "0.1"
//
//scalaVersion := "2.12.8"
//
//val hammockVer = "0.9.0"
//val circeVer = "0.10.0"
//
//scalacOptions ++= Seq(
// "-encoding", "utf8",
// "-Xfatal-warnings",
// "-Ypartial-unification",
// "-deprecation",
// "-unchecked",
// "-language:implicitConversions",
// "-language:higherKinds",
// "-language:existentials",
// "-language:postfixOps"
//)
//libraryDependencies ++= Seq(
// "com.pepegar" %% "hammock-core",
// "com.pepegar" %% "hammock-circe",
// "com.pepegar" %% "hammock-apache-http",
// "com.pepegar" %% "hammock-asynchttpclient",
// "com.pepegar" %% "hammock-akka-http"
//).map(_ % hammockVer) ++ Seq(
// "io.circe" %% "circe-core",
// "io.circe" %% "circe-generic",
// "io.circe" %% "circe-parser"
//).map(_ % circeVer) ++ Seq(
// "io.monix" %% "monix" % "3.0.0-RC2",
// "io.frees" %% "iota-core" % "0.3.10"
//)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment