Is it possible to use Sttp on Scala native?

I’m trying to use Sttp 3 client in Scala native project.
I’ve added these dependencies:

      "com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % "3.8.15",
      "com.softwaremill.sttp.client3" % "cats_native0.4_3" % "3.8.15"

And in my code I’m trying to get backend using:

    HttpClientCatsBackend.resource[IO]().use(backend =>
      IO.println("test").map(_ => ExitCode.Success)

But I’m getting these errors:

[error] Not found Top(sttp.client3.httpclient.cats.HttpClientCatsBackend$)
[error] Not found Member(Top(sttp.client3.httpclient.cats.HttpClientCatsBackend$),D18resource$default$1L31sttp.client3.SttpBackendOptionsEO)
[error] Not found Member(Top(sttp.client3.httpclient.cats.HttpClientCatsBackend$),D18resource$default$2L15scala.Function1EO)
[error] Not found Member(Top(sttp.client3.httpclient.cats.HttpClientCatsBackend$),D18resource$default$3L21scala.PartialFunctionEO)
[error] Not found Member(Top(sttp.client3.httpclient.cats.HttpClientCatsBackend$),D8resourceL31sttp.client3.SttpBackendOptionsL15scala.Function1L21scala.PartialFunctionL24cats.effect.kernel.AsyncL27cats.effect.kernel.ResourceEO)

Is it possible to use client on Scala native? If so, are there any example repos or documentation?

@sergeda The async-http-client-backend-* backend family is not built for scala native. If I read the project correctly, the only supported native backend right now is fs2, could you try it?

Thank you @kciesielski
I updated my imports with

      "com.softwaremill.sttp.client3" %% "async-http-client-backend-fs2" % "3.8.15",
      "com.softwaremill.sttp.client3" % "fs2_native0.4_3" % "3.8.15"

but got similar errors:

[error] Not found Top(sttp.client3.httpclient.fs2.HttpClientFs2Backend$)

Maybe I’m doing something wrong because I saw mentions about usages of sttp client in Scala Native. Just can’t find any working example.

Sorry for misleading, the cats backend you used in your previous question also supports native platform, just like fs2. It’s just the first dependency - async-http-client-backend-* which is unneeded, but let me confirm the exact setup.

1 Like

I’m getting this error when I’m removing “async-http-client-backend-*” dependency:

[error] 9 |import sttp.client3.httpclient.fs2.HttpClientFs2Backend
[error]   |       ^^^^^^^^^^^^^^^^^^^^^^^
[error]   |       value httpclient is not a member of sttp.client3
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

So, not sure where to get the required backend import

@sergeda It turns out mentioned modules are available for native, but they don’t offer full backends. The only backend supported currently on Native is CurlBackend Curl backend — sttp 3 documentation

1 Like

@kciesielski Thank you. Will try this