outwatch-router/docs/index.md

37 lines
788 B
Markdown
Raw Normal View History

---
layout: home
title: "Outwatch Router"
section: "home"
---
Outwatch Router
===
2019-02-04 05:02:45 +00:00
Route creation strategy was mostly taken from Http4s. To create paths and map them to pages:
```scala mdoc
2019-02-04 05:02:45 +00:00
import outwatch.router._
sealed abstract class Page
case class RootPage() extends Page
case class Login() extends Page
case class Register() extends Page
case class Profile(userId: String) extends Page
case class NotFound() extends Page
2019-02-04 05:02:45 +00:00
def routes: PartialFunction[Path, Page] = {
case Root => RootPage()
case Root / "login" => Login()
case Root / "register" => Register()
case Root / "profile" / userId => Profile(userId)
case _ => NotFound()
}
2019-02-04 05:02:45 +00:00
routes(Root)
routes(Root / "login")
routes(Root / "profile" / "saopa98f")
2019-02-04 05:02:45 +00:00
routes(Path("/profile/asd"))
routes(Path("/apsinoasn"))
```