I'm trying to use Binding.scala with an existing http4s backend service, but kind of lost on how they would fit together. I'm not sure how to "bind" a say fs2 Task
or cats-effect IO
with Binding.scala.
Asked
Active
Viewed 397 times
1

Zizheng Tai
- 6,170
- 28
- 79
1 Answers
0
I never used http4s, but a hint could be to use FutureBinding.
As long as you get a Future you can use that quite nicely:
Here my example for calling an async webservice (ajax-call):
@dom def afClients(): Binding[HTMLElement] = {
val apiPath = s"/calendar/afClients"
FutureBinding(Ajax.get(apiPath))
.bind match {
case None =>
<div class="ui active inverted dimmer front">
<div class="ui large text loader">Loading</div>
</div>
case Some(Success(response)) =>
val json = Json.parse(response.responseText)
info(s"Json received List[AFClientConfig]: ${json.toString().take(20)}")
json.validate[List[AFClientConfig]] match {
case JsSuccess(u, _) =>
changeAFClients(u)
<div>
</div>
case JsError(errors) =>
<div>
{s"Problem parsing User: ${errors.map(e => s"${e._1} -> ${e._2}")}"}
</div>
}
case Some(Failure(exception)) =>
error(exception, s"Problem accessing $apiPath")
<div>
{exception.getMessage}
</div>
}
}

pme
- 14,156
- 3
- 52
- 95