Skip to content

Instantly share code, notes, and snippets.

@tomaszperek
Last active October 12, 2015 12:45
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 tomaszperek/6e46db08a65be2038a87 to your computer and use it in GitHub Desktop.
Save tomaszperek/6e46db08a65be2038a87 to your computer and use it in GitHub Desktop.
How concrete directives would look like
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