Steve Harville
Steve Harville

Reputation: 173

How can I use the Scala sttp FetchBackend for handling JavaScript in html?

I need to execute JavaScript in HTML responses. I am using sttp version 1.5.12. According to the documentation I just need to include implicit val sttpBackend = FetchBackend() but it's not working. See documentation at : https://sttp.readthedocs.io/en/latest/backends/javascript/fetch.html

Already included the dependency for Maven.

<!-- https://mvnrepository.com/artifact/com.softwaremill.sttp/core -->
<dependency>
    <groupId>com.softwaremill.sttp</groupId>
    <artifactId>core_2.12</artifactId>
    <version>1.5.12</version>
</dependency>

Example:

import com.softwaremill.sttp._
implicit val sttpBackend = FetchBackend()

I expected to use this like the other supported backends. Eclipse reports not found : value FetchBackend

Any help is appreciated.

Upvotes: 3

Views: 261

Answers (1)

Krzysztof Atłasik
Krzysztof Atłasik

Reputation: 22595

FetchBackend is a wrapper around fetch api which is browser API. You can use it only with scala-js. If you open your link you will notice that dependency of sttp in sbt DSL is using three %, which means that it's version compiled for scala-js:

"com.softwaremill.sttp" %%% "core" % "1.5.12"

With your maven dependency, you're referencing jvm version of sstp, which doesn't contain scala-js specific backends.

You will have to just use another backend for jvm, like akka-http-backend.

Upvotes: 4

Related Questions