Last active
October 12, 2015 12:45
-
-
Save tomaszperek/6e46db08a65be2038a87 to your computer and use it in GitHub Desktop.
How concrete directives would look like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract[L <: HList](f: Request => L): Directive[L] = new Directive[L] { | |
def happly(inner: L ⇒ Route): Route = ctx ⇒ inner(f(ctx))(ctx) | |
} | |
def host: Directive[String :: HNil] = { | |
extract { case Request(url) => | |
val Array(protocol, rest) = url.split("://") | |
rest.split("/", 1).head :: HNil | |
} | |
} | |
def protocol: Directive[String :: HNil] = { | |
extract { case Request(url) => | |
val Array(protocol, rest) = url.split("://") | |
protocol :: HNil | |
} | |
} | |
val protocolAndHost: Directive[String :: String :: HNil] = protocol & host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment