@@ -7,14 +7,35 @@ This library lets you automatically derive Haskell functions that let you query
10+{-# LANGUAGE DataKinds #-}
11+{-# LANGUAGE TypeOperators #-}
15+import Network.HTTP.Client (newManager, defaultManagerSettings)
10type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
22type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
11− :<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books
23+ :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books
13myApi :: Proxy MyApi
25myApi :: Proxy MyApi
14myApi = Proxy
26myApi = Proxy
16−getAllBooks :: Manager -> BaseUrl -> ExceptT String IO [Book]
17−postNewBook :: Book -> Manager -> BaseUrl -> ExceptT String IO Book
18-- 'client' allows you to produce operations to query an API from a client.
28-- 'client' allows you to produce operations to query an API from a client.
29+postNewBook :: Book -> ClientM Book
30+getAllBooks :: ClientM [Book]
19(getAllBooks :<|> postNewBook) = client myApi
31(getAllBooks :<|> postNewBook) = client myApi
36+ manager' <- newManager defaultManagerSettings
37+ res <- runClientM getAllBooks (mkClientEnv manager' (BaseUrl Http "localhost" 8081 ""))
39+ Left err -> putStrLn $ "Error: " ++ show err
40+ Right books -> print books