在http4s后端和Binding.scala前端之间进行通信

问题描述 投票:1回答:1

我正在尝试将Binding.scala与现有的http4s后端服务一起使用,但是它们会如何融合在一起。 我不确定如何用Binding.scala“绑定”说fs2 Task或猫影效IO

scala scala.js http4s binding.scala
1个回答
0
投票

我从未使用过http4s,但提示可能是使用FutureBinding

只要你得到一个未来,你可以很好地使用它:

这是我调用异步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>
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.