From c417ba1d3abaa3d623e9489b43beb7756dda72d7 Mon Sep 17 00:00:00 2001 From: Michal Pawlik Date: Wed, 20 Dec 2023 00:03:05 +0100 Subject: [PATCH] implement cats-effect native backend --- .../client4/impl/cats/CurlCatsBackend.scala | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 effects/cats/src/main/scalanative/sttp/client4/impl/cats/CurlCatsBackend.scala diff --git a/effects/cats/src/main/scalanative/sttp/client4/impl/cats/CurlCatsBackend.scala b/effects/cats/src/main/scalanative/sttp/client4/impl/cats/CurlCatsBackend.scala new file mode 100644 index 0000000000..ff15b9775d --- /dev/null +++ b/effects/cats/src/main/scalanative/sttp/client4/impl/cats/CurlCatsBackend.scala @@ -0,0 +1,26 @@ +package sttp.client4.impl.cats + +import cats.effect.kernel.Sync +import sttp.client4._ +import sttp.client4.curl.internal.CurlApi._ +import sttp.client4.curl.AbstractCurlBackend +import sttp.client4.curl.internal.CurlCode.CurlCode +import sttp.client4.wrappers.FollowRedirectsBackend +import sttp.client4.testing.BackendStub + +class CurlCatsBackend[F[_]: Sync] private ( + verbose: Boolean +) extends AbstractCurlBackend[F](new CatsMonadError, verbose) + with Backend[F] { + + override def performCurl(c: CurlHandle): F[CurlCode] = Sync[F].blocking(c.perform) + +} + +object CurlCatsBackend { + def apply[F[_]: Sync](verbose: Boolean = false): Backend[F] = + FollowRedirectsBackend(new CurlCatsBackend[F](verbose)) + + def stub[F[_]: Sync]: BackendStub[F] = BackendStub(new CatsMonadError) + +}