score:2
Accepted answer
As @jrudolph pointed out, code inside non-leaf extraction directive (like inside pathPrefix("order" / IntNumber) { orderId =>
as it takes orderId
parameter that is gonna be extracted from request) is executed per every request regardless wether or not directives inside are hitting the route. Code inside leaf-directive (like complete
) is executed only when route matches.
To achieve what you probably want, just move your dbService.addParticipant
inside complete
:
pathPrefix("event" / Segment / "user") { id =>
pathEnd {
put {
complete {
dbService.addParticipant(id, user)
"OK"
}
} ~
delete {
complete {
dbService.removeParticipant(id, user)
"OK"
}
}
}
}
Source: stackoverflow.com
Related Query
- Scala Spray Routing - two HTTP method directives executed for single request
- Idiomatic scala for getting a single option out of two Options and throwing exception if two are available
- Play 2.2 for Scala - Modifying AcceptLanguage HTTP Request Header with ScalaInterceptors
- How should I wait for a scala dispatch (0.11.0) http get request to be completed?
- Spray routing works for single slash but nothing else
- Scala futures and method call backs using spray routing
- GREMLIN for Scala : How to drop edge between two vertex and connect edges between two vertex in single query
- Sending two http resonses to client for a single httprequest
- Scala generic method - No ClassTag available for T
- Doing HTTP request in Scala
- Simple and concise HTTP client library for Scala
- What is the rule for parenthesis in Scala method invocation?
- Why are there two sets of arguments/parenthesis in this Scala method definition?
- Scala for loop over two lists simultaneously
- Check for None in Scala Option type isEmpty method
- Scala single method interface implementation
- What is the scala percent operator (%) and at method for strings do?
- "Insecure HTTP request is unsupported" Error in Scala
- How to write copy() method for Simple Class in Scala
- How can I use http request headers for content negotiation in a Mashaller?
- Request was neither completed nor rejected within 1 second Scala Spray Testing
- Why does Scala evaluate the argument for a call-by-name parameter if the method is infix and right-associative?
- How to access a Java static method from Scala given a type alias for that class it resides in
- How can I get a Random URL on http request for Gatling?
- Scala play http filters: how to find the request body
- How do you open a single project for Java, Scala and JRuby in Eclipse?
- Select certain super class for method call in Scala
- Scala Play 2, passing request to method
- Scala - Cannot use a method returning play.api.mvc.Result as a Handler for requests
- How to create a general method for Scala 3 enums
More Query from same tag
- Finagle quickstart client
- Why do I have to import Ordering.Implicits?
- Scala Singleton object for an extended class and pass parameters
- Writing a Custom Class to HDFS in Apache Flink
- How do I group Cassandra rows in Scala
- How can I update a Swing canvas at a certain framerate?
- Inexplicable type mismatch using Scala macros
- How to make Scala's immutable collections hold immutable objects
- Circle json generic in trait
- Using chardet to detect bad encoding in a MySQL db with JDBC
- String interpolation: f or s
- How to dynamically generate numbers in play template?
- TypeError: 'JavaPackage' object is not callable for Xgboost in PySpark
- In scala, Can I say Future and Promise are also kind of monad?
- Can I move stackable trait logic to parent?
- Why does Scala occasionally fall back to Java objects?
- Explode Cassandra UDT with flatmap in Spark 2.x (Scala)
- Why the following Scala code does not compile unless explicit type parameters are added?
- Why do I need parentheses here?
- Dynamic conversion of Array of double columns into multiple columns in nested spark dataframe
- Scala collections: Is there a safe map operation?
- How to time how long it takes for Akka HTTP to complete HTTP request
- How can I verify type existence on compile time in Scala
- In Scala how do you update a property of an object within an array of objects, the object being selected by the user
- Config library which allows to define scopes
- Spark Scala update dataframe
- Scala: How to avoid using the existential type
- Getting command-line arguments in Scala traits
- How to use Spark-SQL query for implementing conditional statement?
- jackson databind Json serialization is writing Some(99): Option[Int] as {"empty":true,"defined":false}