Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-kushikatsu
Simple routing with Kushiyaki.
https://github.com/justinwoo/purescript-kushikatsu
parsing purescript routing type-level
Last synced: 8 days ago
JSON representation
Simple routing with Kushiyaki.
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-kushikatsu
- Owner: justinwoo
- Created: 2018-05-15T21:23:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-05T14:33:11.000Z (over 6 years ago)
- Last Synced: 2024-10-11T10:10:52.524Z (about 1 month ago)
- Topics: parsing, purescript, routing, type-level
- Language: PureScript
- Homepage:
- Size: 3.91 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PureScript-Kushikatsu
Simple routing with [Kushiyaki](https://github.com/justinwoo/purescript-kushiyaki).
Wrapped kushiyaki is kushikatsu:
![](https://i.imgur.com/GC18feC.jpg)
Requires PureScript 0.12
## Usage
Setup:
```hs
type RouteURLs =
( hello :: RouteURL "/hello/{name}"
, age :: RouteURL "/age/{age:Int}"
, answer :: RouteURL "/gimme/{item:String}/{count:Int}"
)main :: Effect Unit
main = do
let snoc' a xs = Array.snoc xs a
ref <- Ref.new []let
-- inferred type:
-- (matchRoutes' :: String
-- -> Either
-- NoMatch
-- (Variant
-- ( hello :: { name :: String}
-- , age :: { age :: Int }
-- , answer :: { item :: String , count :: Int }
-- )
-- )
-- ) =
matchRoutes' =
matchRoutes (RProxy :: RProxy RouteURLs)testRoutes =
[ "/hello/Bill"
, "/age/12"
, "/gimme/Apple/24"
, "/no/match"
]matched = matchRoutes' <$> testRoutes
handleResult = case _ of
Left (NoMatch l) -> do
Ref.modify_ (snoc' $ "no match: " <> l) ref
Right r ->
Variant.match
{ hello: \x -> Ref.modify_ (snoc' x.name) ref
, age: \x -> Ref.modify_ (snoc' $ show x.age) ref
, answer: \x -> Ref.modify_ (snoc' $ show x.count <> "," <> x.item) ref
}
rtraverse_ handleResult matched
actual <- Ref.read ref
let
expected =
[ "Bill"
, "12"
, "24,Apple"
, "no match: /no/match"
]
assertEqual { actual, expected }
```