繁体   English   中英

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

[英]Communicate between http4s backend and Binding.scala frontend

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

我从未使用过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>
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM