Cherry
Cherry

Reputation: 33544

Is there a directive receiving all HTTP methods in spray?

The example with HTTP GET with spray 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>
        }
      }
    }
  }
}

So if I want execute HTTP POST I can use the post directive. But how can I deliver response to all HTTP methods? Something like this:

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

Is there all directive or something similar?

Upvotes: 0

Views: 98

Answers (1)

mohit
mohit

Reputation: 4999

get is a filter directive to filter HTTP methods and allows only get to pass through. You don't need to have any filter directive.

So to allow all you can just not have any filter directive based on HTTP methods


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

Upvotes: 2

Related Questions