Permalink
Browse files

Emit some random JSON.

  • Loading branch information...
1 parent 63bcbb0 commit a208b97e295d705886405e1dd6bf811c13632f0f @therealadam committed Feb 10, 2013
Showing with 36 additions and 1 deletion.
  1. +3 −0 project/build.scala
  2. +1 −0 src/main/scala/ScalatraBootstrap.scala
  3. +32 −1 src/main/scala/stella/StellaServlet.scala
View
3 project/build.scala
@@ -22,6 +22,9 @@ object StellaByStarlightBuild extends Build {
scalaVersion := ScalaVersion,
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
libraryDependencies ++= Seq(
+ "com.github.nscala-time" %% "nscala-time" % "0.2.0",
+ "org.scalatra" %% "scalatra-json" % "2.2.0",
+ "org.json4s" %% "json4s-jackson" % "3.1.0",
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
View
1 src/main/scala/ScalatraBootstrap.scala
@@ -7,3 +7,4 @@ class ScalatraBootstrap extends LifeCycle {
context.mount(new StellaServlet, "/*")
}
}
+
View
33 src/main/scala/stella/StellaServlet.scala
@@ -3,11 +3,42 @@ package stella
import org.scalatra._
import scalate.ScalateSupport
-class StellaServlet extends StellaByStarlightStack with ScalateSupport {
+import com.github.nscala_time.time.Imports._
+import org.json4s.{DefaultFormats, Formats}
+import org.scalatra.json._
+
+class StellaServlet extends StellaByStarlightStack with JacksonJsonSupport {
+ protected implicit val jsonFormats: Formats = DefaultFormats
+
+ before() {
+ contentType = formats("json")
+ }
get("/") {
contentType = "text/html"
ssp("index")
}
+ get("/api/metrics") {
+ MetricData.generate
+ }
+
}
+
+case class Metric(value: String, timestamp: String)
+
+object MetricData {
+
+ var all = List(
+ Metric("123", DateTime.now.toString()),
+ Metric("456", DateTime.now.toString()),
+ Metric("789", DateTime.now.toString()),
+ Metric("456", DateTime.now.toString())
+ )
+
+ def generate = {
+ 1 to 1000 map { i => Metric(i.toString(), DateTime.now.toString()) }
+ }
+
+}
+

0 comments on commit a208b97

Please sign in to comment.