Check quickstart below, or this Main.scala for a Scala 3
flavoured example.
For further examples checkout the tests.
Note: Previous versions are available on branch 0.7.x
For latest version check the maven badge above. For other versions check: https://search.maven.org/search?q=org.purang.net or https://repo1.maven.org/maven2/org/purang/net/
libraryDependencies += "org.purang.net" %% "asynch" % "3.2.1" //we tend to follow scala 3's version if possible
Checkout Main.scala
import org.purang.net.http.asynchttpclient.AsyncHttpClient
import org.asynchttpclient.{
DefaultAsyncHttpClientConfig,
DefaultAsyncHttpClient,
AsyncHttpClient => UnderlyingHttpClient
}
import cats.data.NonEmptyChain
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import cats.syntax.show._
import java.util.concurrent.TimeUnit
@main def start(): Unit =
val req = GET > "https://httpbin.org/delay/0" >> Headers(NonEmptyChain(Accept(ApplicationJson)))
val config = new DefaultAsyncHttpClientConfig.Builder()
.setCompressionEnforced(true)
.setConnectTimeout(500)
.setRequestTimeout(3000)
.setCookieStore(null)
.build()
val underlyingclient: UnderlyingHttpClient = new DefaultAsyncHttpClient(config)
println((for {
c <- AsyncHttpClient.sync[IO](
underlyingclient
)
r <- c.execute(
req,
Timeout(2000, TimeUnit.MILLISECONDS)
)
} yield r.show).attempt.unsafeRunSync())
Critique is sought actively. Help will be provided keenly. Contributions are welcome. Install simple build tool 1+, fork the repo and get hacking.
licenses += ("BSD", url("http://www.tldrlegal.com/license/bsd-3-clause-license-%28revised%29"))
Use at your own risk. See LICENSE for more details.