【问题标题】:Is there a directive receiving all HTTP methods in spray?是否有一个指令可以接收所有的 HTTP 方法?
【发布时间】:2015-01-24 08:37:09
【问题描述】:

HTTP GET 示例与喷雾is simple

import spray.routing.SimpleRoutingApp

object Main extends App with SimpleRoutingApp {
  implicit val system = ActorSystem("my-system")

  startServer(interface = "localhost", port = 8080) {
    path("hello") {
      get {
        complete {
          <h1>Say hello to spray</h1>
        }
      }
    }
  }
}

所以如果我想执行 HTTP POST,我可以使用 post 指令。但是我怎样才能对所有的 HTTP 方法做出响应呢?像这样的:

startServer(interface = "localhost", port = 8080) {
path("hello") {
  all { // - here something like all derective
    complete ("I do not care.")
    }
  }
}

是否有all 指令或类似的指令?

【问题讨论】:

    标签: scala routing spray


    【解决方案1】:

    get 是一个过滤器指令,用于过滤 HTTP 方法,并且只允许 get 通过。您不需要任何过滤器指令。

    所以为了让所有你不能有任何基于 HTTP 方法的过滤指令

    
    import spray.routing.SimpleRoutingApp
    object Main extends App with SimpleRoutingApp {
      implicit val system = ActorSystem("my-system")
      startServer(interface = "localhost", port = 8080) {
        path("hello") {
          complete {
              Say hello to spray
          }
        }
      }
    }

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 2010-12-24
      • 1970-01-01
      • 2021-09-03
      • 2012-11-18
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多