【问题标题】:Communicate between http4s backend and Binding.scala frontend在 http4s 后端和 Binding.scala 前端之间进行通信
【发布时间】:2017-11-22 08:31:30
【问题描述】:

我正在尝试将 Binding.scala 与现有的 http4s 后端服务一起使用,但对它们如何组合在一起有点迷茫。我不知道如何用 Binding.scala “绑定”说 fs2 Task 或猫效应 IO

【问题讨论】:

    标签: scala scala.js http4s binding.scala


    【解决方案1】:

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

    只要你有一个 Future,你就可以很好地使用它:

    这是我调用异步 Web 服务(ajax 调用)的示例:

      @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>
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 2022-08-11
      • 2014-07-20
      • 1970-01-01
      相关资源
      最近更新 更多