Advertisement
Guest User

Untitled

a guest
Mar 21st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.74 KB | None | 0 0
  1. /**
  2.  * Created by Edmund on 2015-03-21.
  3.  */
  4.  
  5. import org.scalatra._
  6. import scalate.ScalateSupport
  7.  
  8. import scala.collection.mutable
  9. import scala.language.postfixOps
  10.  
  11. // JSON-related libraries
  12.  
  13. import org.json4s.{DefaultFormats, Formats}
  14.  
  15. // JSON handling support from Scalatra
  16.  
  17. import org.scalatra.json._
  18.  
  19. class MyScalatraServlet extends ScalatraServlet with JacksonJsonSupport {
  20.  
  21.   protected implicit val jsonFormats: Formats = DefaultFormats
  22.  
  23.   before() {
  24.     contentType = formats("json")
  25.   }
  26.  
  27.   case class Datas(name: String)
  28.  
  29.   val datast = mutable.ListBuffer(
  30.     Datas("Blank")
  31.   )
  32.  
  33.   get("/") {
  34.     datast
  35.   }
  36.  
  37.   post("/") {
  38.     val newDatas = parsedBody.extractOpt[Datas]
  39.     newDatas foreach {datast +=}
  40.   }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement