Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to use → in route pattern, in addition to -> #2109

Merged
merged 2 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dsl/src/main/scala/org/http4s/dsl/Http4sDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ trait Http4sDsl[F[_]] extends Http4s with Methods with Statuses with Responses[F
val /: : impl./:.type = impl./:
val +& : impl.+&.type = impl.+&

/**
* Alias for `->`.
*
* Note: Due to infix operation precedence, `→` has a lower priority than `/`. So you have to use parentheses in
* pattern matching when using this operator.
*
* For example:
* {{{
* (request.method, Path(request.path)) match {
* case Method.GET → (Root / "test.json") => ...
* }}}
*/
val → : impl.->.type = impl.->

val IntVar: impl.IntVar.type = impl.IntVar
val LongVar: impl.LongVar.type = impl.LongVar
val UUIDVar: impl.UUIDVar.type = impl.UUIDVar
Expand Down
8 changes: 8 additions & 0 deletions dsl/src/test/scala/org/http4s/dsl/PathSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class PathSpec extends Http4sSpec {
}) must beTrue
}

"→ extractor /test.json" in {
val req = Request[IO](method = Method.GET, uri = uri("/test.json"))
(req match {
case GET → (Root / "test.json") => true
case _ => false
}) must beTrue
}

"request path info extractor for /" in {
val req = Request[IO](method = Method.GET, uri = uri("/"))
(req match {
Expand Down