Commit 7ec78e0d authored by julien dehos's avatar julien dehos

add endpoint

parent 8c35c2a9
......@@ -49,6 +49,7 @@ homeRoute m = div_
[ h1_ [] [ text "miso-xhr" ]
, ul_ [] (map fmtHero $ heroes_ m)
, p_ [] [ a_ [href_ $ ms $ show linkHeroes] [ text "JSON data" ] ]
, p_ [] [ a_ [href_ $ ms $ show $ linkAdd 20 22 ] [ text "add 20 22" ] ]
, p_ [] [ a_ [href_ "https://gitlab.com/juliendehos/miso-xhr"] [ text "source code" ] ]
]
where fmtHero h = li_ []
......@@ -58,16 +59,23 @@ homeRoute m = div_
]
type StaticApi = "static" :> Raw
type AddApi = "add" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Int
type HeroesApi = "heroes" :> Get '[JSON] [Hero]
type PublicApi = StaticApi :<|> HeroesApi
type PublicApi = StaticApi :<|> AddApi :<|> HeroesApi
fetchStatic :: Method -> ClientM Response
fetchAdd :: Int -> Int -> ClientM Int
fetchHeroes :: ClientM [Hero]
fetchStatic :<|> fetchHeroes = client (Proxy @PublicApi)
fetchStatic :<|> fetchAdd :<|> fetchHeroes = client (Proxy @PublicApi)
linkStatic :: URI
linkStatic = linkURI $ safeLink (Proxy @PublicApi) (Proxy @StaticApi)
linkAdd :: Int -> Int -> URI
linkAdd x y = linkURI (safeLink (Proxy @PublicApi) (Proxy @AddApi) x y)
linkHeroes :: URI
linkHeroes = linkURI $ safeLink (Proxy @PublicApi) (Proxy @HeroesApi)
-- TODO linkAdd
......@@ -25,15 +25,20 @@ main = do
type ServerApi
= StaticApi
:<|> AddApi
:<|> HeroesApi
:<|> ToServerRoutes ClientRoutes HtmlPage Action
server :: Server ServerApi
server
= serveDirectoryFileServer "static"
:<|> handleAdd
:<|> pure heroes
:<|> (pure $ HtmlPage $ homeRoute initialModel)
handleAdd :: Int -> Int -> Handler Int
handleAdd x y = pure $ x + y
heroes :: [Hero]
heroes =
[ Hero "Scooby Doo" "scoobydoo.png"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment