Skip to content

Commit

Permalink
Cleanup & Readme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vkostyukov committed Aug 9, 2014
1 parent 5812b15 commit e4b400a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ object Hello extends Service[HttpRequest, HttpResponse] {
}
```

### Redirects

There is a tiny factory object `io.finch.response.Redirect` that may be used for generation redirect services.
Here is the example:

```scala
val e = new Endpoint[HttpRequest, HttpResponse] = {
def route = {
case Method.Get -> Root / "users" / name => GetUser(name)
case Method.Get -> Root / "Bob" => Redirect("/users/Bob") // or with path object
}
}
```

Bonus Track: JSON on Steroids
-----------------------------

Expand Down
8 changes: 3 additions & 5 deletions src/main/scala/io/finch/response/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ package object response {
*
* @return A Service that generates a redirect to the given url
*/
def apply(url: String): Service[HttpRequest, HttpResponse] = {
new Service[HttpRequest, HttpResponse] {
override def apply(request: HttpRequest) = SeeOther.withHeaders(("Location", url))().toFuture
}
def apply(url: String) = new Service[HttpRequest, HttpResponse] {
def apply(req: HttpRequest) = SeeOther.withHeaders(("Location", url))().toFuture
}

/**
Expand All @@ -142,6 +140,6 @@ package object response {
*
* @return A Service that generates a redirect to the given path
*/
def apply(path: Path): Service[HttpRequest, HttpResponse] = this(path.toString)
def apply(path: Path) = this(path.toString)
}
}

0 comments on commit e4b400a

Please sign in to comment.