首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >http4s后端和Binding.scala前端之间的通信

http4s后端和Binding.scala前端之间的通信
EN

Stack Overflow用户
提问于 2017-06-20 09:04:01
回答 1查看 352关注 0票数 1

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

EN

回答 1

Stack Overflow用户

发布于 2018-01-26 03:40:25

我从未使用过http4s,但可以给出一个提示,可以使用FutureBinding

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

下面是我调用异步Here服务的示例(ajax-call):

代码语言:javascript
复制
  @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>
    }
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44642173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档