Advertisement
Guest User

Untitled

a guest
Aug 15th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.98 KB | None | 0 0
  1.  val jsonRoute = {
  2.       import spray.httpx.SprayJsonSupport.sprayJsonMarshaller
  3.       import spray.httpx.SprayJsonSupport.sprayJsonUnmarshaller
  4.       import JsonImplicits._
  5.  
  6.     get {
  7.       path("") {
  8.         respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here
  9.           complete {
  10.             <html>
  11.               <body>
  12.                 <h1>The <b>S4</b> - <i>Slick Spray Scala Stack</i> is running :-)</h1>
  13.               </body>
  14.             </html>
  15.           }
  16.         }
  17.       } ~
  18.         path("index") {
  19.           respondWithMediaType(`text/html`) {
  20.                       complete {
  21.             <html>
  22.               <body>
  23.                 <h1>Fix this</h1>
  24.               </body>
  25.             </html>
  26.           }
  27.           }
  28.         } ~
  29.         path("index2") {
  30.           respondWithMediaType(`text/html`) {
  31.                       complete {
  32.             <html>
  33.               <body>
  34.                 <h1>Fix this also</h1>
  35.               </body>
  36.             </html>
  37.           }
  38.           }
  39.         }
  40.     } ~
  41.       //          unmatchedPath { ump =>
  42.       //        redirect("bootstrap/%s" + ump, Found)
  43.       //      }
  44.       get {
  45.         //   path("favicon.ico") {
  46.         //    complete(NotFound)
  47.         //  } ~
  48.         path(Rest) { path =>
  49.           getFromResource("bootstrap/%s" format path)
  50.         } ~
  51.           path("file") {
  52.             getFromResource("application.conf")
  53.           }
  54.       } ~
  55.       path("persons") {
  56.         get { ctx =>
  57.           ctx.complete {
  58.             val result: List[Person] = m.getPersons()
  59.             result
  60.           }
  61.         }
  62.       } ~
  63.       path("person") {
  64.         authenticate(BasicAuth(CustomUserPassAuthenticator, "person-security-realm")) { userProfile =>
  65.           post {
  66.             entity(as[Person]) { person => ()
  67.               val result: Person = m.addPerson(person)
  68.               complete(result)
  69.             }
  70.           }
  71.         }
  72.       }
  73.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement