Scala Dispatch REST GET示例

时间:2014-04-03 12:36:55

标签: scala rest scala-dispatch

我有一个客户端对暴露REST API的服务器进行REST调用。以下是我迄今为止实施的内容:

  override def getData[T](reqURL: String, requestParam: Option[Seq[(String, String)]])(responseHandler: T => Unit) = {

    val onSuccess: PartialFunction[String, Unit] = {
      case s => responseHandler(s.asInstanceOf[T])
    }
    val onFailure: PartialFunction[Throwable, Unit] = {
      case e => e.printStackTrace
    }

    val request = requestParam match {
      case Some(params) => url(reqURL).as_!("user", "pass") <<? params
      case None         => url(reqURL).as_!("user", "pass")
    }
    Http(request OK as.String).onSuccess(onSuccess).onFailure(onFailure)
  }

它工作得非常好,但我注意到即使在呼叫完成后HTTP连接也是打开的。我该如何关闭此连接?我可能想在onSuccess或onFailure调用发生后执行此操作。有什么建议吗?

0 个答案:

没有答案