|
@@ -1,10 +1,11 @@
|
|
package scruffy.examples
|
|
package scruffy.examples
|
|
|
|
|
|
import com.mongodb.casbah.Imports._
|
|
import com.mongodb.casbah.Imports._
|
|
-import com.sksamuel.scruffy.EndpointProvider
|
|
|
|
|
|
+import com.sksamuel.scruffy.HttpEndpointProvider
|
|
|
|
|
|
/** @author Stephen Samuel */
|
|
/** @author Stephen Samuel */
|
|
-class Test2Endpoint() extends EndpointProvider {
|
|
|
|
|
|
+class Test2Endpoint() extends HttpEndpointProvider {
|
|
|
|
+
|
|
val hostname = "database_host"
|
|
val hostname = "database_host"
|
|
val connection = MongoConnection(hostname, 27017)
|
|
val connection = MongoConnection(hostname, 27017)
|
|
val collection = connection.getDB("hello_world").getCollection("world")
|
|
val collection = connection.getDB("hello_world").getCollection("world")
|
|
@@ -16,12 +17,13 @@ class Test2Endpoint() extends EndpointProvider {
|
|
//for ( k <- 1 to 10000 )
|
|
//for ( k <- 1 to 10000 )
|
|
// collection.save(DBObject("_id" -> k, "id" -> k, "randomNumber" -> random.nextInt(10000).toDouble))
|
|
// collection.save(DBObject("_id" -> k, "id" -> k, "randomNumber" -> random.nextInt(10000).toDouble))
|
|
|
|
|
|
- get("db").json {
|
|
|
|
- req =>
|
|
|
|
|
|
+ get("db") { implicit req =>
|
|
|
|
+ json {
|
|
val id = random.nextInt(10000)
|
|
val id = random.nextInt(10000)
|
|
val dbo = collection.findOne(DBObject("_id" -> id), fields)
|
|
val dbo = collection.findOne(DBObject("_id" -> id), fields)
|
|
val randomNumber = Math.round(dbo.get("randomNumber").toString.toFloat)
|
|
val randomNumber = Math.round(dbo.get("randomNumber").toString.toFloat)
|
|
Output(id, randomNumber)
|
|
Output(id, randomNumber)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|