Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created June 12, 2012 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislewis/2919454 to your computer and use it in GitHub Desktop.
Save chrislewis/2919454 to your computer and use it in GitHub Desktop.
package com.example.foobie
import unfiltered.jetty.Http
import unfiltered.response._
import unfiltered.request._
trait Resolver[A] {
type B
}
object Format {
def unapply[A](req: HttpRequest[A])(implicit resolver: Resolver[A]) = {
val f = (pf: PartialFunction[HttpRequest[A], ResponseFunction[resolver.B]]) => pf(req)
Some(f)
}
}
object App {
implicit val servlet = new Resolver[javax.servlet.http.HttpServletRequest] {
type B = javax.servlet.http.HttpServletResponse
}
def main(args: Array[String]) {
Http(8080).plan(unfiltered.filter.Planify {
case Format(f) => f {
case Accepts.Json(_) => JsonContent ~> ResponseString("{}")
case _ => ResponseString("ko")
}
/*case req => req match {
case Accepts.Json(_) => JsonContent ~> ResponseString("{}")
case _ => ResponseString("ko")
}*/
}) run()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment